Active Record, Get A Single Sql-Query From A Single Table

Hi, I’m new to yii and have a simple question. I have 1 table and my the one who is log-in is sessioned I want to return all entries of the sessioned user it is determined by the userid

Here is my controller




	public function actionViewUserPost()

	{

		$model=new ContentForm;

		$dataProvider=new CActiveDataProvider('ContentForm');

		$try->userid=Yii::app()->session['iduser'];

		// $record=Yii::model()->findByAttributes(array('userid' => $_POST['userid']));

		

		

		// find(array(

			// 'select'=>'title, content',

			// 'condition'=>'iduser=userid',

			// 'params'=>array(':userid'=>$_POST['ContentForm'])));

		// $dataProvider=new CActiveDataProvider('ContentForm', array(

		// 'criteria' => array(

				// 'with'=> array ()

		// )

		// )

		// $posts=ContentForm::model()->findByPk(59);

		// findAll($userid=Yii::app()->session['iduser'];,$params);


		$this->render('viewuserpost',array(

			'dataProvider'=>$dataProvider,

			'userid'=>$try,

		));

	}



the commented parts are the one i’ve tried bud didnt work.

Here is my view:

viewuserpost.php




<?php

echo "I am view user post";


$this->widget('zii.widgets.CListView', array(

	'dataProvider'=>$dataProvider,

	'itemView'=>'_view',

)); 


?>



_view.php




<div class="view">


	<b><?php echo CHtml::encode($data->getAttributeLabel('contentid')); ?>:</b>

	<?php echo CHtml::encode($data->contentid); ?>

	<br />


	<b><?php echo CHtml::encode($data->getAttributeLabel('title')); ?>:</b>

	<?php echo CHtml::encode($data->title); ?>

	<br />


	<b><?php echo CHtml::encode($data->getAttributeLabel('content')); ?>:</b>

	<?php echo CHtml::encode($data->content); ?>

	<br />


	<b><?php echo CHtml::encode($data->getAttributeLabel('userid')); ?>:</b>

	<?php echo CHtml::encode($data->userid); ?>

	<br />


</div>



What I am trying to do is when kim = userid 8 is logged in only the entries of kim would be shown in the view. please help

if ContentForm is model class related to user table then below code should work.


$posts=ContentForm::model()->findByPk(59);

and if not then use


$data=User::model()->findByPk($id);

and then render view with $data object. This could be done without using CActiveDataProvider




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

  'criteria' => array(

    'condition' => 'iduser = :userId',

    'params' => array(':userId' => Yii::app()->session['iduser']),    

  ),

));