CListView

So guys here comes that line that you read all the time:

I’m new with yii and i need help please

So that said this is my case:

I have a table User and a table Survey in the same database. The user create surveys and when it happens the user saves his id in the table survey. Untill there everything fine. The trouble appears when i try to show the surveys with the crud list surveys. I will see all the surveys of the data base and not only the surveys that the user created.

i*ve been trying with something like this code but i get errors all the time.

if (Yii::app()->user->id == Yii::app()->survey->id){

… Show list

}

I was thinking as well to go trough the data provider searching for the data that has the id of the user (Yii::app()->user->id) save that in an extra array and then send it to the CListView. I’m understanding wrong how the ClistView works or i’m just totally lost on what i said?

$this->widget(‘zii.widgets.CListView’, array(‘dataProvider’=>$dataProvider, //here is the problem, i need an array with the surveys of the user that is logged in

‘itemView’=>’_view’,

‘sortableAttributes’=>array(

                                                                  'title',


                                                                  'start_date',


                                                                  'end_date',


                                                        ),

Any advice?

you are on the right track here

here is an example


<?php

public function actionMySurvey()

{

	// currently logged in user id

	$userID = Yii::app()->user->id;

	// create a new criteria

	$criteria = new CDbCriteria;

	// compare the userid with logged in user id

	$criteria->compare('user_id', $userID);


	$dataProvider=new CActiveDataProvider('Survey',array(

			'criteria'=>$criteria

	));


	$this->render("mySurvey", array("dataProvider" => $dataProvider));

}

when i try to put that code i become some sort of errors. This is the whole code of that site. When i activate this lines

$criteria = new CDbCriteria;

$dataProvider = new CActiveDataProvider(‘Survey’,array(‘criteria’=>$criteria)

i get this error.

syntax error, unexpected T_VARIABLE in line 37 ( where the dataProvider comes into the widget)

What i’m doing wrong?

<?php

/* @var $this SurveyController */

/* @var $dataProvider CActiveDataProvider */

/* here we have to make a search of the list of surveys of the user that is logged in . This should help if (Yii::app()->user->id == Yii::app()->survey->id)*/

$this->breadcrumbs=array(

'Surveys',

);

$this->menu=array(

array('label'=&gt;'Create Survey', 'url'=&gt;array('create')),


array('label'=&gt;'Manage Survey', 'url'=&gt;array('admin')),

);

?>

<h1>Surveys</h1>

<?php

    &#036;userID = Yii::app()-&gt;user-&gt;id;





    // create a new criteria


    &#036;criteria = new CDbCriteria;





    // compare the userid with logged in user id


    &#036;criteria-&gt;compare('user_id', &#036;userID);





  &#036;dataProvider = new CActiveDataProvider('Survey',array('criteria'=&gt;&#036;criteria)





  //  &#036;this-&gt;render(&quot;mySurvey&quot;, array(&quot;dataProvider&quot; =&gt; &#036;dataProvider,itemView'=&gt;'_view','sortableAttributes'=&gt;array  ('title','start_date','end_date' ) );

$this->widget (‘zii.widgets.CListView’, array (‘dataProvider’=>$dataProvider,‘itemView’=>’_view’,‘sortableAttributes’=>array (‘title’,‘start_date’,‘end_date’ ) ) );

?>