开发者

Fatal error: Call to a member function trigger() on a non-object in .../model.php on line 2106 when running as CakeTestCase

开发者 https://www.devze.com 2023-02-14 11:06 出处:网络
I\'m a newbie to PHP, CakePHP, and the CakePHP unit testing framework for 1.3. I created a simple test case of a model and ran into this error:

I'm a newbie to PHP, CakePHP, and the CakePHP unit testing framework for 1.3.

I created a simple test case of a model and ran into this error:

Fatal error: Call to a member function trigger() on a non-object in /Users/calvinc/Sites/lhasa/web/cake/libs/model/model.php on line 2106

I notice that the line 2106 in model.php is as follows:

  if ($query['callbacks'] === true || $query['callbacks'] === 'before') {
      $return = $this->Behaviors->trigger($this, 'beforeFind', array($query), array(

I'm guessing that Behaviors is not setup. What would be the cause of that?

Here's the dump of the Login object.

[Wed Mar 02 11:06:26 2011] [error] [client 127.0.0.1] Login Object ( [actsAs] => Array ( [0] => Containable )

[utcOffset] => 8
[useDbConfig] => default
[useTable] => 
[displayField] => 
[id] => 
[data] => Array
    (
    )

[table] => 
[primaryKey] => 
[_schema] => 
[validationErrors] => Array
    (
    )

[tablePrefix] => 
[name] => 
[alias] => 
[tableToModel] => Array
    (
    )

[logTransactions] => 
[cacheQueries] => 
[belongsTo] => Array
    (
    )

[hasOne] => Array
    (
    )

[hasMany] => Array
    (
    )

[hasAndBelongsToMany] => Array
    (
    )

[Behaviors] => 
[whitelist] => Array
    (
    )

[cacheSources] => 1
[findQueryType] => 
[recursive] => 1
[order] => 
[virtualFields] => Array
    (
    )

[__associationKeys] => Array
    (
        [belongsTo] => Array
            (
                [0] => className
                [1] => foreignKey
                [2] => conditions
                [3] => fields
                [4] => order
                [5] => counterCache
            )

        [hasOne] => Array
            (
                [0] => className
                [1] => foreignKey
                [2] => conditions
                [3] 开发者_开发百科=> fields
                [4] => order
                [5] => dependent
            )

        [hasMany] => Array
            (
                [0] => className
                [1] => foreignKey
                [2] => conditions
                [3] => fields
                [4] => order
                [5] => limit
                [6] => offset
                [7] => dependent
                [8] => exclusive
                [9] => finderQuery
                [10] => counterQuery
            )

        [hasAndBelongsToMany] => Array
            (
                [0] => className
                [1] => joinTable
                [2] => with
                [3] => foreignKey
                [4] => associationForeignKey
                [5] => conditions
                [6] => fields
                [7] => order
                [8] => limit
                [9] => offset
                [10] => unique
                [11] => finderQuery
                [12] => deleteQuery
                [13] => insertQuery
            )

    )

[__associations] => Array
    (
        [0] => belongsTo
        [1] => hasOne
        [2] => hasMany
        [3] => hasAndBelongsToMany
    )

[__backAssociation] => Array
    (
    )

[__insertID] => 
[__numRows] => 
[__affectedRows] => 
[_findMethods] => Array
    (
        [all] => 1
        [first] => 1
        [count] => 1
        [neighbors] => 1
        [list] => 1
        [threaded] => 1
    )

)


I think that your problem ... is my problem. So .. my problem was that I had a method inside of my model with the same name of my model.

class Ranking extends AppModel {
   function ranking($a)....
}

This was making the PHP interpret the function as constructor, so the AppModel constructor was not being called. And our model did have not the data correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消