1

I have a folowing code in my controller ,

   public function actionViewJob() {

        $user_id = Yii::app()->session['user_id'];
        /* For User Authentication */
        if (Yii::app()->user->getId() === null)
            $this->redirect(array('site/login'));
        /* For User Authentication */

         $model=ViewJob::model()->findAll(array('user_id'=>Yii::app()->user->id));
        $params = array('model' => $model,
        );

        $this->render('viewjob', $params);

I am getting error /* Property "CDbCriteria.user_id" is not defined. */ but when I am using findByAttrinute its working f9,but I not getting the result,i.e its not filtering data,pls help.

view section :

// not posting full code //


   <?php
        $this->widget('zii.widgets.grid.CGridView', array(
            'dataProvider' =>$model->search(),  

'columns' => array(
            array(
                'name' => 'title',
                'type' => 'raw',
                'value' => 'CHtml::encode($data->title)',
                'htmlOptions' => array('style'=>'width:90px;','class'=>'zzz'),
               // 'filter'=>'false' /* for hiding filter boxes */

         ),?>
tereško
  • 58,060
  • 25
  • 98
  • 150
saji
  • 201
  • 1
  • 5
  • 19
  • Please add your `viewjob` view for the filtering. – topher Apr 11 '14 at 10:34
  • here is my full question http://stackoverflow.com/questions/23008830/retreving-specific-row-from-database-in-yii/23009094?noredirect=1#comment35145848_23009094 – saji Apr 11 '14 at 10:37
  • also this: http://stackoverflow.com/questions/22961153/getting-a-particular-row-from-database-in-yii/22961606?noredirect=1#comment35069305_22961606 – saji Apr 11 '14 at 10:38
  • 1
    Hi. Please refrain from adding any more questions. I will mark all 3 as duplicates. – topher Apr 11 '14 at 10:42
  • Also, add the `viewjob` code to this question. For more info: https://stackoverflow.com/faq – topher Apr 11 '14 at 10:45
  • ok,sorry..I will take care of that in future...just posted my view section,pls do have a look... – saji Apr 11 '14 at 11:21

1 Answers1

2

Wrong method. You should use CActiveRecord::findAllByAttributes() instead

$model=ViewJob::model()->findAllByAttributes(array('user_id'=>Yii::app()->user->id));

Or if you still want to use findAll you should pass the attribute in as a condition:

$model=ViewJob::model()->findAll('user_id=:user_id',array(':user_id'=>Yii::app()->user->id));

Now for the view:

dataProvider expects an instance of CDataProvider. CActiveRecord::search() returns one such instance: CActiveDataProvider. However, $model is an array not an instance of CActiveRecord. You have two choices here:

a) You can to edit your controller to use $model as a ViewJob instance and not an array of ViewJob instances:

public function actionViewJob() {

    $user_id = Yii::app()->session['user_id'];
    /* For User Authentication */
    if (Yii::app()->user->getId() === null)
        $this->redirect(array('site/login'));
    /* For User Authentication */

    $model= new ViewJob;
    $model->user_id = $user_id;
    $params = array('model' => $model,
    );
    ...

b) Replace the $model->search() in the view with

    'dataProvider' => new CArrayDataProvider($model)

Choice (b) is easier but it breaks conventions e.g $model is an array not an object. Also any filters/search functionality has to be added manually as opposed to using the default functionality provided by CActiveRecord::search().

topher
  • 14,790
  • 7
  • 54
  • 70
  • topher..but its not filtering the data...displaying all the row from table.Where I want to display only a specific row from table.how can I do that. – saji Apr 11 '14 at 10:34
  • It worked...thanks a lot topher,...was stuck for almost two days. – saji Apr 12 '14 at 05:42