This 3 tables are just a part of my entire project (users,profile,login)
Login.php (model for login table)
public function topten_logins(){
$criteria = new CDbCriteria;
$criteria->select = 'concat(u.firstname," ",u.lastname) as Name, p.join_date as Joined, count(*) as Logins';
$criteria->alias = 'l';
$criteria->join = 'left join users u on (u.id = l.user_id) left join profile p on (p.user_id = l.user_id)';
$criteria->group = 'l.user_id';
$criteria->order = 'Logins desc';
$criteria->limit = '10';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
and I have to display it in CGridView, and my code to display is as follows:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>Login::model()->topten_logins(),
'enablePagination' => false,
'columns'=>array(
'Name',
'Joined',
'Logins',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
I just want to display Top ten users who have most logins.
But it gives me error message that:
Property “Login.Name” is not defined.
I haven’t used Yii before. So, your help will be highly appreciated.
The problem is you are making query with ‘as Name and as Logins’. In this case, what you need to do is to define ‘Name’ and ‘Logins’ as a variable in your model. in the class definition of your model add
And it should work.