how to do that please help…
this is my controller
I think this is what you could be looking for CActiveRecord::findAllByAttributes()
There are many ways to approach this problem take look at this might help you
<?php
// first approach
...
$criteria = new CDbCriteria;
$criteria->compare("price", 1);
$posts = Post::model()->find($criteria);
...
// second approach
...
$posts = Post::model()->find(array('price'=>1));
...
doesn’t work, in which functions must put this code, what variable must have that function. Exists a clear example.
For exemple in your PostsController change your actionIndex() this way
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Post',array('criteria'=>array('condition'=>"price =1")));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
And don’t forget to learn about CActiveDataProvider
second approach is not valid
it should be:
$posts = Post::model()->findByAttributes(array('price'=>1));
or
$posts = Post::model()->find('price = :price, 'array(':price'=>1));
or
$posts = Post::model()->find(array('condition'=>'price = :price', 'params'=>array(':price'=>1)));
as say api for find function:
If an array, it is treated as the initial values for constructing a CDbCriteria object; Otherwise, it should be an instance of CDbCriteria.
It works…Billion of thanks.
happy to know that it helped you
redjohn u must read the blog tutorial