i am creating a new search feature as first feature on Yii to understand the flow and working of framework.
here is what i did.
-
I created a model and extended CFormModel
-
I defined variables and wrote a function for search using Query builder
code:
public function searchQuery(){
$command = Yii::app()->db->createCommand() //code that do the search query
->select('*')
->from('tbl_restaurant_info')
->where('restaurant_name=:restaurant_name') //I am not sure if i am doing this right!
->queryAll();
- Here is what i wrote in controller
Code
$model = new SearchForm;
if (isset($_POST['SearchForm']))
{
$model->attributes=$_POST['SearchForm'];
$viewdata = array(
'dataprovider'=> $model->searchQuery(), //I am trying to store the output of query
);
$this->render('SearchResult',array('model'=>$viewdata));
}
else{
$this->render('SearchForm',array('model'=>$model));
}
4)In view I want to output the search result
code
var_dump($model['dataprovider']);
I have an input form which takes the user input and is getting posted in $_POST[‘SearchForm’]
I see the output as null.
please help me understand where i am going wrong. I do not understand,where the output of search query being stored and how it will be retrieved and how to bind variable value in the where clause of sql.
Thanks.