Yii Framework Forum: Admin view by loggin in user? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Admin view by loggin in user? Rate Topic: -----

#1 User is offline   ficti0n 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 31-May 10

Posted 04 June 2010 - 04:54 PM

How and where would I setup the admin section to ONLY view the records associated with the logged in users ID?

I am already passing the id in Yii::app()->user->id....

I want to say

<?php if($model->memberId === Yii::app()->user->id){?>
List those records


Where do I make that change?? In the model, view, or the controller??? And how?

I think I figured out where to do this but it doesnt work!!!

public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Member', array(
'criteria'=>array(
'condition'=>'memberId === Yii::app()->user->id',
'with'=>array('team'),

),


???????????? When I do that, it brings back everything not just the current user id.... it shouldnt be pulling all that data though
0

#2 User is offline   ficti0n 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 31-May 10

Posted 04 June 2010 - 05:46 PM

Hmmmm actually can I do this via calling the search action??? and when the user logs into the admin page it searches automatically and shows only thier items????
0

#3 User is offline   tydeas_dr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 16-April 10
  • Location:Greece

Posted 05 June 2010 - 03:46 PM

View Postficti0n, on 04 June 2010 - 05:46 PM, said:

Hmmmm actually can I do this via calling the search action??? and when the user logs into the admin page it searches automatically and shows only thier items????

Don't think it's a good idea the above.

What you are going to do is in the controller of the your first though is correct.
CDbCriteria should look like.
$criteria=new CDbCriteria(array(
'condition'=>'status= :memberidparameter',
'params'=>array(':memberidparameter'=>$memb) , //i am not sure if the must be an array there.
));


What this differs from yours and think this is the error is
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Member', array(
'criteria'=>array(
'condition'=>'memberId [size="4"]===Yii::app()->user->id [/size]',
'with'=>array('team'),

),


don't forget tha the condition is

Quote

query condition. This refers to the WHERE clause in an SQL statement. For example, age>31 AND team=1.
so === don't help and finally if it would you then going to make this equal with the string Yii::app()->user->id NOT the val.
This is why you have it in '' and not outside.
Follow me on twitter @dmtrsslvdr
Check my *new* blog @ tumblr
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users