Php 致命错误:对非对象调用成员函数getDbCriteria()
我使用的是Yii 1.1.15,出现了这个错误Php 致命错误:对非对象调用成员函数getDbCriteria(),php,yii,Php,Yii,我使用的是Yii 1.1.15,出现了这个错误 致命错误:对非对象调用成员函数getDbCriteria() 我认为下面的代码是正确的 <?php $model = new Comment(); //name of my model Project refers to Mysql innoDB table tblproject. $daten=$model::model();
致命错误:对非对象调用成员函数getDbCriteria()
我认为下面的代码是正确的
<?php
$model = new Comment(); //name of my model Project refers to Mysql innoDB table tblproject.
$daten=$model::model();
$dataProvider=new CActiveDataProvider($daten->with(array('posts' => array('limit'=>6)))->findAll());
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view_latest_comment', //view file location
));
?>
更新:
我也尝试过这个,但它没有将限制设置为5
$model = new Comment();
$daten=$model::model();
$criteria = new CDbCriteria;
$criteria->limit=5;
$dataProvider=new CActiveDataProvider($daten, array('criteria'=>$criteria));
当iprint\r($daten)时代码>我明白了
Comment Object (
[_type:Comment:private] =>
[_key:Comment:private] =>
[_make:Comment:private] =>
[_model:Comment:private] =>
[_year:Comment:private] =>
[_new:Comment:private] =>
[_attributes:CActiveRecord:private] => Array ( )
[_related:CActiveRecord:private] => Array ( )
[_c:CActiveRecord:private] =>
[_pk:CActiveRecord:private] =>
[_alias:CActiveRecord:private] => t
[_errors:CModel:private] => Array ( )
[_validators:CModel:private] =>
[_scenario:CModel:private] =>
[_e:CComponent:private] => Array (
[onbeforesave] => CList Object (
[_d:CList:private] => Array (
[0] => Array (
[0] => CTimestampBehavior Object (
[createAttribute] => createDate
[updateAttribute] =>
[setUpdateOnCreate] =>
[timestampExpression] =>
[_enabled:CBehavior:private] => 1
[_owner:CBehavior:private] => Comment Object *RECURSION*
[_e:CComponent:private] =>
[_m:CComponent:private] => )
[1] => beforeSave ) )
[_c:CList:private] => 1
[_r:CList:private] =>
[_e:CComponent:private] =>
[_m:CComponent:private] => ) )
[_m:CComponent:private] => Array (
[commentable] => CommentableBehavior Object (
[mapTable] =>
[mapCommentColumn] => commentId
[mapRelatedColumn] =>
[mapMakeColumn] => make_code
[mapModelColumn] => model_code
[mapYearColumn] => year_made
[mapVariantColumn] => variant
[_enabled:CBehavior:private] => 1
[_owner:CBehavior:private] => Comment Object *RECURSION*
[_e:CComponent:private] =>
[_m:CComponent:private] => )
[CTimestampBehavior] => CTimestampBehavior Object (
[createAttribute] => createDate
[updateAttribute] =>
[setUpdateOnCreate] =>
[timestampExpression] =>
[_enabled:CBehavior:private] => 1
[_owner:CBehavior:private] => Comment Object *RECURSION*
[_e:CComponent:private] =>
[_m:CComponent:private] => ) )
[_new:CActiveRecord:private] => )
我正在尝试动态设置返回结果的限制,但似乎无法使其正常工作。知道我做错了什么或错过了什么吗?感谢数据提供程序要求第一个参数为类名或模型实例。在您看来,这是findAll()
的结果
将带有
子句的移动到第二个参数,如下所示:
<?php
$dataProvider = new CActiveDataProvider(Comment::model(), array(
'criteria' => array(
'with' => array('posts')
)));
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view_latest_comment', //view file location
));
这可能会帮助你@KirenSiva尝试过它。它没有设置限制,但这次没有错误。更新了问题TooGetDbCriteria函数从何处调用?@PeterM页面刚刚死亡,它显示了以下致命错误:调用成员函数getDbCriteria()在第225行的/Applications/XAMPP/xamppfiles/htdocs/dev/common/lib/yii/framework/web/cactivedaptrovider.php中的非对象上
@PratipGhosh我没有调用getDbCriteria的代码。当我搜索我的项目时,唯一找到的getDbCriteria
位于dev/common/lib/yii/framework/db/ar/CActiveFinder.php
中,它仍然没有限制输出。是因为self::有很多关系吗<代码>$dataProvider=新的CActiveDataProvider(Comment::model(),数组('criteria'=>array('with'=>array('posts'=>array('limit'=>2))))代码>这完全是另一回事,我建议如果你在限制方面还有问题,可以问新问题。也许您必须在标准中设置限制
数组?通常,dataprovider会自行设置其限制/偏移量,因此dataprovider可能会对此进行验证。
<?php
$dataProvider = new CActiveDataProvider(Comment::model(), array(
'criteria' => array(
'with' => array('posts')
)));
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view_latest_comment', //view file location
));
$dataProvider=new CActiveDataProvider('Post', array(
'criteria'=>array(
'condition'=>'status=1',
'order'=>'create_time DESC',
'with'=>array('author'),
),
'countCriteria'=>array(
'condition'=>'status=1',
// 'order' and 'with' clauses have no meaning for the count query
),
'pagination'=>array(
'pageSize'=>20,
),
));