以下是我的查询如何在yii中放置视图,模型,控制器中的代码
select productid, count(*)
from fc_member
group by productid
order by count(*)desc
LIMIT 3
请让我知道我是新手 我确实尝试过,但不知道如何以及它是什么:(
控制器
public function actiondsplayproduct()
{
$model=new Member;
$dataProvider=new CActiveDataProvider('$model',
array(
'criteria'=>array(
'select'=>'productid, COUNT( * )as Cproductid',
'from'=>'fc_member',
'group'=>'productid',
'order'=>'COUNT( * ) ',
),
)
);
$this->render('dsplayproduct',array(
'dataProvider'=>$dataProvider,
));
//$this->render('dsplayproduct',array('model'=>$model));
}
查看
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=> $dataProvider,
'filter'=>$model,
'columns'=>array(
'productid',
'Cproductid',
)
));
并且还得到以下错误
PHP警告
include($model.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
请让我知道我是新手
我确实尝试但后来不知道它是怎么回事:(
跟随r d更改
model
`public function top_selling_products() {
$criteria = new CDbCriteria;
$criteria->select = 'productid , count(*) as pid_count';
$criteria->from='fc_member';
$criteria->group = 'productid';
$criteria->order = 'pid_count desc';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}`
controoler
`
public function actiondsplayproduct()
{
$dataProvider=new CActiveDataProvider('Member');
$this->render('dsplayproduct',array(
'dataProvider'=>$dataProvider,
));
}
view
$ this-&gt; widget('zii.widgets.grid.CGridView',array(
'dataProvider'=>Member::model()->top_selling_products(),
'enablePagination' => false,
'columns'=>array(
'pid',
'pid_count',
array(
'class'=>'CButtonColumn',
),
),
)); `
但是我得到了以下错误
未定义属性“CDbCriteria.from”。
Plz让我现在我错了
答案 0 :(得分:0)
我认为它不是你想要放入$model
类的字符串CActiveDataProvider
...
所以,它不是
CActiveDataProvider('$model', ...
但是
CActiveDataProvider('model', ...
或者
CActiveDataProvider($model, ...
答案 1 :(得分:0)
错误说你没有&#34; $ model.php&#34;文件 - 因此您必须为模型文件添加有效和现有名称。
例如:
new CActiveDataProvider('model', ...