Limited Access For Index That Made Of ​​The Crud

I have a text model. The controller made ​​crud . Now the index would like to limit users to see themselves not just as Notes all see now that the

I want to make changes. That each user only sees his own posts

<?php

class TextController extends Controller

{

/**


 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning


 * using two-column layout. See 'protected/views/layouts/column2.php'.


 */


public &#036;layout='//layouts/column2';





/**


 * @return array action filters


 */


public function filters()


{


	return array(


		'accessControl', // perform access control for CRUD operations


		'postOnly + delete', // we only allow deletion via POST request


	);


}





/**


 * Specifies the access control rules.


 * This method is used by the 'accessControl' filter.


 * @return array access control rules


 */


public function accessRules()


{


	return array(


		array('allow',  // allow all users to perform 'index' and 'view' actions


			'actions'=&gt;array('index','view'),


			'users'=&gt;array('*'),


		),


		array('allow', // allow authenticated user to perform 'create' and 'update' actions


			'actions'=&gt;array('create','update'),


			'users'=&gt;array('@'),


		),


		array('allow', // allow admin user to perform 'admin' and 'delete' actions


			'actions'=&gt;array('admin','delete'),


			'users'=&gt;array('admin'),


		),


		array('deny',  // deny all users


			'users'=&gt;array('*'),


		),


	);


}





/**


 * Displays a particular model.


 * @param integer &#036;id the ID of the model to be displayed


 */


public function actionView(&#036;id)


{


	&#036;this-&gt;render('view',array(


		'model'=&gt;&#036;this-&gt;loadModel(&#036;id),


	));


}





/**


 * Creates a new model.


 * If creation is successful, the browser will be redirected to the 'view' page.


 */


public function actionCreate()


{


	&#036;model=new Text;





	// Uncomment the following line if AJAX validation is needed


	// &#036;this-&gt;performAjaxValidation(&#036;model);





	if(isset(&#036;_POST['Text']))


	{


		&#036;model-&gt;attributes=&#036;_POST['Text'];


		if(&#036;model-&gt;save())


			&#036;this-&gt;redirect(array('view','id'=&gt;&#036;model-&gt;id));


	}





	&#036;this-&gt;render('create',array(


		'model'=&gt;&#036;model,


	));


}





/**


 * Updates a particular model.


 * If update is successful, the browser will be redirected to the 'view' page.


 * @param integer &#036;id the ID of the model to be updated


 */


public function actionUpdate(&#036;id)


{


	&#036;model=&#036;this-&gt;loadModel(&#036;id);





	// Uncomment the following line if AJAX validation is needed


	// &#036;this-&gt;performAjaxValidation(&#036;model);





	if(isset(&#036;_POST['Text']))


	{


		&#036;model-&gt;attributes=&#036;_POST['Text'];


		if(&#036;model-&gt;save())


			&#036;this-&gt;redirect(array('view','id'=&gt;&#036;model-&gt;id));


	}





	&#036;this-&gt;render('update',array(


		'model'=&gt;&#036;model,


	));


}





/**


 * Deletes a particular model.


 * If deletion is successful, the browser will be redirected to the 'admin' page.


 * @param integer &#036;id the ID of the model to be deleted


 */


public function actionDelete(&#036;id)


{


	&#036;this-&gt;loadModel(&#036;id)-&gt;delete();





	// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser


	if(&#33;isset(&#036;_GET['ajax']))


		&#036;this-&gt;redirect(isset(&#036;_POST['returnUrl']) ? &#036;_POST['returnUrl'] : array('admin'));


}





/**


 * Lists all models.


 */


public function actionIndex()


{


	&#036;dataProvider=new CActiveDataProvider('Text');


	&#036;this-&gt;render('index',array(


		'dataProvider'=&gt;&#036;dataProvider,


	));


}





/**


 * Manages all models.


 */


public function actionAdmin()


{


	&#036;model=new Text('search');


	&#036;model-&gt;unsetAttributes();  // clear any default values


	if(isset(&#036;_GET['Text']))


		&#036;model-&gt;attributes=&#036;_GET['Text'];





	&#036;this-&gt;render('admin',array(


		'model'=&gt;&#036;model,


	));


}





/**


 * Returns the data model based on the primary key given in the GET variable.


 * If the data model is not found, an HTTP exception will be raised.


 * @param integer &#036;id the ID of the model to be loaded


 * @return Text the loaded model


 * @throws CHttpException


 */


public function loadModel(&#036;id)


{


	&#036;model=Text::model()-&gt;findByPk(&#036;id);


	if(&#036;model===null)


		throw new CHttpException(404,'The requested page does not exist.');


	return &#036;model;


}





/**


 * Performs the AJAX validation.


 * @param Text &#036;model the model to be validated


 */


protected function performAjaxValidation(&#036;model)


{


	if(isset(&#036;_POST['ajax']) &amp;&amp; &#036;_POST['ajax']==='text-form')


	{


		echo CActiveForm::validate(&#036;model);


		Yii::app()-&gt;end();


	}


}

}


<?php

/**

  • This is the model class for table "text".

  • The followings are the available columns in table ‘text’:

  • @property integer $id

  • @property string $subject

  • @property string $matn

  • @property string $group

  • @property integer $user_id

  • @property integer $Privacy

  • The followings are the available model relations:

  • @property Users $user

*/

class Text extends CActiveRecord

{

/**


 * @return string the associated database table name


 */


public function tableName()


{


	return 'text';


}





/**


 * @return array validation rules for model attributes.


 */


public function rules()


{


	// NOTE: you should only define rules for those attributes that


	// will receive user inputs.


	return array(


		array('subject, user_id, Privacy', 'required'),


		array('user_id, Privacy', 'numerical', 'integerOnly'=&gt;true),


		array('subject', 'length', 'max'=&gt;80),


		array('matn', 'length', 'max'=&gt;255),


		array('group', 'length', 'max'=&gt;20),


		// The following rule is used by search().


		// @todo Please remove those attributes that should not be searched.


		array('id, subject, matn, group, user_id, Privacy', 'safe', 'on'=&gt;'search'),


	);


}





        public function getidX()


          


  {





        &#036;user= Yii::app()-&gt;db-&gt;createCommand();

// SELECT users.username from users INNER JOIN text on text.user_id=users.id

     //   SELECT users.username FROM users,  text  WHERE users.id=text.user_id;


 &#036;user = Yii::app()-&gt;db-&gt;createCommand()


-&gt;select('users.id')


-&gt;from('users')


-&gt;where('users.id=:username' , array(':username'=&gt;1))

// ->where(‘id=:id’, array(’:id’=>$id))

-&gt;queryRow();


return &#036;user;


  }





  


  


  


  


  


/**


 * @return array relational rules.


 */


public function relations()


{


	// NOTE: you may need to adjust the relation name and the related


	// class name for the relations automatically generated below.


	return array(


		'user' =&gt; array(self::BELONGS_TO, 'Users', 'user_id'),


	);


}





/**


 * @return array customized attribute labels (name=&gt;label)


 */


public function attributeLabels()


{


	return array(


		'id' =&gt; 'ID',


		'subject' =&gt; 'Subject',


		'matn' =&gt; 'Matn',


		'group' =&gt; 'Group',


		'user_id' =&gt; 'User',


		'Privacy' =&gt; 'Privacy',


	);


}





/**


 * Retrieves a list of models based on the current search/filter conditions.


 *


 * Typical usecase:


 * - Initialize the model fields with values from filter form.


 * - Execute this method to get CActiveDataProvider instance which will filter


 * models according to data in model fields.


 * - Pass data provider to CGridView, CListView or any similar widget.


 *


 * @return CActiveDataProvider the data provider that can return the models


 * based on the search/filter conditions.


 */


public function search()


{


	// @todo Please modify the following code to remove attributes that should not be searched.





	&#036;criteria=new CDbCriteria;





	&#036;criteria-&gt;compare('id',&#036;this-&gt;id);


	&#036;criteria-&gt;compare('subject',&#036;this-&gt;subject,true);


	&#036;criteria-&gt;compare('matn',&#036;this-&gt;matn,true);


	&#036;criteria-&gt;compare('group',&#036;this-&gt;group,true);


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


	&#036;criteria-&gt;compare('Privacy',&#036;this-&gt;Privacy);





	return new CActiveDataProvider(&#036;this, array(


		'criteria'=&gt;&#036;criteria,


	));


}





/**


 * Returns the static model of the specified AR class.


 * Please note that you should have this exact method in all your CActiveRecord descendants&#33;


 * @param string &#036;className active record class name.


 * @return Text the static model class


 */


public static function model(&#036;className=__CLASS__)


{


	return parent::model(&#036;className);


}

}


<?php

/* @var $this TextController */

/* @var $dataProvider CActiveDataProvider */

$this->breadcrumbs=array(

'Texts',

);

$this->menu=array(

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


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

);

?>

<h1>Texts</h1>

<?php $this->widget(‘zii.widgets.CListView’, array(

'dataProvider'=&gt;&#036;dataProvider,


'itemView'=&gt;'_view',

)); ?>

I want to make changes. That each user only sees his own posts

move index accessRule to authenticated user (’@’)

and logic in actionIndex to load Post models posted by Yii::app()->user->id.