Database-Live-Search Doesn't Work As Expected

Hello everyone!

I’m following exactly the instructions in this extention post:

  1. copy jquery.js into js folder( the folder is located under my project folder, inside where index.php in located).

  2. add 2 functions to HotelController:

        //this one is added by me. Is used for freeSearch

        public function actionFreeSearch()


            $model=new Hotel('search');

            $this->render('freeSearch', array('model'=>$model));


        // this one is also added by me. Is used for freeSearch

        public function actionSearchEngine($keyword)


            //  echo "THIS IS IAJAXX  ".$keyword;

            $model=new Hotel();

            $model->unsetAttributes();  // clear any default values






  1. add the following code to accessRules() of HotelController:

// this is added for freeSearch

array('allow', // allow authenticated user to perform 'create' and 'update' actions                       actions'=>array('create','update','InboundSearch','OutboundSearch','admin','FreeSearch','SearchEngine'),



  1. add new function freeSearch to Hotel model:

        //this one is added by me. Is used for freeSearch

        public function freeSearch($keyword)


            /*Creating a new criteria for search*/

            $criteria = new CDbCriteria;


            $criteria->compare('hotel_name', $keyword, true, 'OR');

            $criteria->compare('hotel_id', $keyword, true, 'OR');

            //$criteria->compare('part_number', $keyword, true, 'OR');

            /*result limit*/

            $criteria->limit = 100;

            /*When we want to return model*/

            return  Hotel::model()->findAll($criteria);

            /*To return active dataprovider uncomment the following code*/


            return new CActiveDataProvider($this, array(





Here I modified table fields to my fields hotel_name and hotel_id.

5.add two new views freeSearch.php and _ajax_search.php


<body onload="document.search_form.query.focus()">


    /*To import the client script*/

    $baseUrl = Yii::app()->baseUrl; 

    $cs = Yii::app()->getClientScript();




<div class="admin"> 

<script type="text/javascript"> 

    $(document).ready(function() { 



            var faq_search_input = $(this).val();

            var dataString = 'keyword='+ faq_search_input;

            var ref_id = $('#ref_id').val(); 

            var cust_id = $('#cust_id').val(); 

            var current_url = $('#current_url').val(); 

            /*This is the minimum size of search string. Search will be only done when at-least 3 characters are provided in input*/




                    type: "GET",

                    url: current_url+"/SearchEngine",

                    data: dataString,

                    /*Uncomment this if you want to send the additional data*/

                    //data: dataString+"&refid="+ref_id+"&custid="+cust_id,

                    beforeSend:  function(){



                    success: function(server_response)




                        if ($('input#faq_search_input').hasClass("loading")) {






            return false;






    /*You need to change the URL as per your requirements, else this will show error page*/



    /*To Send the additional data if needed*/

    $reference_id = 88;

    $customer_id = 77;

    //echo "Search   :".$current_url;



    <input type="hidden" id="current_url" value="<?php echo $current_url;?>"/> 


    <input type="hidden" id="ref_id" value="<?php echo $reference_id ;?>"/> 

    <input type="hidden" id="cust_id" value="<?php echo $customer_id ;?>"/>  

    Enter Hotel<br><br>

    <!-- The Searchbox Starts Here  -->

    <form  name="search_form">

        <input  name="query" type="text" id="faq_search_input" style="background-color: #FFFFFF" />


    <!-- The Searchbox Ends  Here  -->

    <div id="searchresultdata" class="faq-articles"> </div>


Here every thing still remains

And this is [b]_ajax_search.php



    foreach ($results as $row)


        echo "<br>";

        echo "Name: ".$row['hotel_name']."   ";

        echo "Hotel id ".$row['hotel_id']."   ";



To explain more I’ve attached 2 pics:

First one is when I’m typing “asia” in the text field.

The live search is not working like google does.



Second picture shows that the _ajax_search view doesn’t show up. And we’re back to homepage for some reason.



Very painful!

I’ve searched in the forum, some people have faced this issue but sounds like nothing has been resolved.

This is very handy and powerful tool (in my opinion) but I’m very surprised because the number of posts related to the extension is very few in our forum. On the extension page I see Downloaded: 575 times. Maybe every body has no problem getting this extension to work?

Anyway thank you for your time and look forward to see any reply from you!




I have an additionnal question about this part :

/You need to change the URL as per your requirements, else this will show error page/



Could someone please provide an example of what to enter here ?

Right now when I try and reach the freeSearch view, I get a 403 error.

Thanks :)



I’m also looking into this extension. Hope we can find a way to make this work.



Anyone plz help me . I can’t fix this issue .