bonnie
(Africanbusinesszone)
August 17, 2011, 7:20pm
1
Hi, to all any help will be appreciated. I have the actionAdmin in my controller and CGridView as follows.
I need to show only the listings for the current logged in user and not show the listings that belongs to the other user. I give all the rights view, update and delete in the ‘CButtonColumn’. Just want to show the record for the user that is logged in if he/she created an listing and display Not found if no record found. I have a link Manage Listings that should be clicked before showing this CgridView. I tried the following in the actionAdmin but does not work.
/**
* Manages all models.
*/
public function actionAdmin()
{
$model = new Listings('search');
if($model->author_id == Yii::app()->user->id){
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Listings']))
$model->attributes=$_GET['Listings'];
}
$this->render('admin',array(
'model'=>$model,
));
}
And my CGridView I have
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
//'filter' => $model->author_id == Yii::app()->user->id,
'columns'=>array(
array(
'name' => 'year',
'type' => 'raw',
'value' => 'CHtml::link(CHtml::encode($data->year), $data->url)'
),
array(
'name' => 'make',
'type' => 'raw',
'value' => 'CHtml::link(CHtml::encode($data->make->make), $data->url)'
),
array(
'name' => 'status',
'value' => 'AutoLookup::item("PostStatus", $data->status)',
'filter' => AutoLookup::items('ListStatus'),
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
bonnie
(Africanbusinesszone)
August 28, 2011, 10:22pm
2
bonnie:
Hi, to all any help will be appreciated. I have the actionAdmin in my controller and CGridView as follows.
I need to show only the listings for the current logged in user and not show the listings that belongs to the other user. I give all the rights view, update and delete in the ‘CButtonColumn’. Just want to show the record for the user that is logged in if he/she created an listing and display Not found if no record found. I have a link Manage Listings that should be clicked before showing this CgridView. I tried the following in the actionAdmin but does not work.
/**
* Manages all models.
*/
public function actionAdmin()
{
$model = new Listings('search');
if($model->author_id == Yii::app()->user->id){
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Listings']))
$model->attributes=$_GET['Listings'];
}
$this->render('admin',array(
'model'=>$model,
));
}
And my CGridView I have
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
//'filter' => $model->author_id == Yii::app()->user->id,
'columns'=>array(
array(
'name' => 'year',
'type' => 'raw',
'value' => 'CHtml::link(CHtml::encode($data->year), $data->url)'
),
array(
'name' => 'make',
'type' => 'raw',
'value' => 'CHtml::link(CHtml::encode($data->make->make), $data->url)'
),
array(
'name' => 'status',
'value' => 'AutoLookup::item("PostStatus", $data->status)',
'filter' => AutoLookup::items('ListStatus'),
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
I got it working the way i need by placing this peace of code in the method search in the model
$criteria->compare('author_id', Yii::app()->user->id, $partialMatch = false);
This will give me all the posts or whatever that has been posted by the current logged in in a CGridView
kenhmusic
(Kenhmusic)
October 30, 2011, 9:58am
3
This is just what I was looking for. Thanks for sharing.
dniznick
(Dniznick)
October 30, 2011, 9:54pm
4
You can also use defaultScope to force the find() methods to add a WHERE clause automatically.