my first feature and writing mvc

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.

  1. I created a model and extended CFormModel

  2. I defined variables and wrote a function for search using Query builder


        public function searchQuery(){

        $command = Yii::app()->db->createCommand()     //code that do the search query



        ->where('restaurant_name=:restaurant_name')    //I am not sure if i am doing this right!

  1. Here is what i wrote in controller


        $model = new SearchForm;

        if (isset($_POST['SearchForm']))



        $viewdata = array(

            'dataprovider'=> $model->searchQuery(),       //I am trying to store the output of query  








4)In view I want to output the search result



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.


Clearly searchQuery() is empty. Does it have a proper ‘return’?


$model = new SearchForm;

if (isset($_POST['SearchForm']))


  $data = $model->searchQuery();



Hi Spritespirit,

In addition what Backslider said I noticed that you need to add a binded value, e.g.

->where('restaurant_name=:restaurant_name', array(':restaurant_name'=>$restaurantName))

Of course you’ll need to have [color="#1C2837"][size=“2”]$restaurantName variable set beforehand.[/size][/color]

And please don’t forget to use code formatting next time. Simplifies reading ;)