Searching

Hello I am a newbie in yii and I dont know how search work here’s my code

[size="5"]VIEW[/size]

<style>

.xxx


{


    padding: 3px;


    float: left;


    width:33.33%;


    color: #808080;


    /*font-family: Calibri, Candara, Segoe, 'Segoe UI', Optima, Arial, sans-serif;*/


}


.tabledata{


    visibility: visible;


    font-family: Calibri, Candara, Segoe, 'Segoe UI', Optima, Arial, sans-serif;


}


thead {


    font-size: 9.5pt;


}


input#mainto,select#active {


    display: inline;


}

</style>

<div class="clear"> </div>

<div class="xxx"><input type="text" class="form-control" placeholder="Reference No." name="refno" id="mainto"></div>

<div class="xxx"><input type="text" class="form-control" placeholder="Production Code" name="prodcode"></div>

<div class="xxx"><input type="text" class="form-control" placeholder="Production Description" name="proddesc"></div>

<div class="xxx"><input type="text" class="form-control" placeholder="Item Code" name="itemcode"></div>

<div class="xxx"><input type="text" class="form-control" placeholder="Jo No." name="jono"></div>

<div class="xxx">

&lt;select class=&quot;form-control&quot; name=&quot;lsdstatus&quot;&gt;


    &lt;option value=&quot;&quot;&gt;LSD Status&lt;/option&gt;


    &lt;?php


    &#036;lsdstat=lsdstatus::model()-&gt;findAll();


    foreach(&#036;lsdstat as &#036;lsdstat){


        echo '&lt;option value='.&#036;lsdstat-&gt;id.'&gt;'.&#036;lsdstat-&gt;name.'&lt;/option&gt;';


    }


    ?&gt;&lt;/select&gt;

</div>

<div class="xxx">

&lt;select class=&quot;form-control&quot; name=&quot;jobstatus&quot;&gt;


    &lt;option value=&quot;&quot;&gt;Job Status&lt;/option&gt;


    &lt;?php


    &#036;jobstat=jobstatus::model()-&gt;findAll();


    foreach( &#036;jobstat as &#036;jobstat){


        echo '&lt;option value='.&#036;jobstat-&gt;id.'&gt;'.&#036;jobstat-&gt;name.'&lt;/option&gt;';


    }


    ?&gt;&lt;/select&gt;

</div>

<div class="xxx">

&lt;select class=&quot;form-control&quot; name=&quot;customername&quot;&gt;


    &lt;option value=&quot;&quot;&gt;Customer Name&lt;/option&gt;


    &lt;?php


    &#036;cname=customer::model()-&gt;findAll();


    foreach( &#036;cname as &#036;cname){


        echo '&lt;option value='.&#036;cname-&gt;id.'&gt;'.&#036;cname-&gt;name.'&lt;/option&gt;';


    }


    ?&gt;&lt;/select&gt;


&lt;br /&gt;

</div>

<div class="xxx">

&lt;?php echo CHtml::submitButton(&#036;model-&gt;isNewRecord ? 'Search' : 'Save',array('class'=&gt;'btn btn-primary','name'=&gt;'search')); ?&gt;


&lt;?php echo CHtml::submitButton(&#036;model-&gt;isNewRecord ? 'Clear Search' : 'Clear Search',array('class'=&gt;'btn btn-primary','name'=&gt;'clearsearch')); ?&gt;

</div>

<div class="tabledata">

  &lt;table class=&quot;table table-hover table-bordered&quot;&gt;


      &lt;tr&gt;


          &lt;thead&gt;


         &#60;&#33;-- &lt;th&gt;#&lt;/th&gt;--&#62;


          &lt;th&gt;Reference No.&lt;/th&gt;


         &lt;th&gt;Item Code&lt;/th&gt;


          &#60;&#33;--&lt;th&gt;Old Reference No.&lt;/th&gt;--&#62;


          &lt;th&gt;Customer Name&lt;/th&gt;


          &lt;th&gt;Product Code&lt;/th&gt;


          &lt;th&gt;Product description&lt;/th&gt;





          &lt;th&gt;Jo No&lt;/th&gt;


          &lt;th&gt;LSD Status&lt;/th&gt;


          &lt;th&gt;&lt;/th&gt;


          &lt;/thead&gt;


      &lt;/tr&gt;


      &lt;tbody&gt;


      &lt;br /&gt;

<?php

foreach($mainview as $main) {/<td>’ . $main[‘id’]. ’ </td><td>’ . $main[‘oldreferenceno’]. ’ </td>/

// $main = onlinecolortolerance::model()->findByAttributes(array(‘id’ => $main->id));

echo ' &lt;tr&gt;





     &lt;td&gt;' . &#036;main['newreferenceno']. ' &lt;/td&gt;


    &lt;td&gt;' . &#036;main['itemcode']. ' &lt;/td&gt;


    &lt;td &gt;' . &#036;main['customername']. ' &lt;/td&gt;


    &lt;td&gt;' . &#036;main['productcode']. ' &lt;/td&gt;


     &lt;td&gt;' . &#036;main['productdescription']. ' &lt;/td&gt;





    &lt;td&gt;' . &#036;main['jono']. ' &lt;/td&gt;


    &lt;td&gt;' . &#036;main['lsdstatus']. ' &lt;/td&gt;


    &lt;td nowrap&gt;'.CHtml::link('Select',array('site/index'),array('class'=&gt;'btn btn-primary')).'&lt;/td&gt;


     &lt;/tr&gt;';

}?>

      &lt;/tbody&gt;


  &lt;/table&gt;

</div>

[size="6"]Controler[/size]

<?php

class OnlinecolortoleranceController extends Controller

{

public function actionIndex()


{


	&#036;this-&gt;render('index');


}





// Uncomment the following methods and override them if needed





public function filters()


{


    return array(


        'accessControl', // perform access control for CRUD operations


        'postOnly + delete', // we only allow deletion via POST request


    );


}





public function actions()


{


	// return external action classes, e.g.:


	return array(


		'action1'=&gt;'path.to.ActionClass',


		'action2'=&gt;array(


			'class'=&gt;'path.to.AnotherActionClass',


			'propertyName'=&gt;'propertyValue',


		),


	);


}


public function accessRules()


{


    return array(


        array('allow',  // allow all users to perform 'index' and 'view' actions


            'actions'=&gt;array('index','view','Main'),


            'users'=&gt;array('*'),


        ),


        array('allow', // allow authenticated user to perform 'create' and 'update' actions


            'actions'=&gt;array('create','update','main'),


            'users'=&gt;array('@'),


        ),


        array('allow', // allow admin user to perform 'admin' and 'delete' actions


            'actions'=&gt;array('admin','delete','main'),


            'users'=&gt;array('admin'),


        ),


        array('deny',  // deny all users


            'users'=&gt;array('*'),


        ),





    );


}


public function actionAdmin()


{


    &#036;model=new Issue('search');


    &#036;model-&gt;unsetAttributes();  // clear any default values


    if(isset(&#036;_GET['Issue']))


        &#036;model-&gt;attributes=&#036;_GET['Issue'];

// Assign value for the project_id attribute of $model object by filling it with associated project_id of the issue

// This would restrict admin search for only current project context

    &#036;model-&gt;project_id = &#036;this-&gt;_project-&gt;id;





    &#036;this-&gt;render('admin',array(


        'model'=&gt;&#036;model,


    ));


}

public function actionMain()

{





    &#036;criteria= new CDbCriteria;


    if(isset(&#036;_POST['search'])){


        &#036;criteria-&gt;condition= 'id&#33;=0';


        if(&#036;_POST['refno']&#33;=null){


            &#036;criteria-&gt;condition= &#036;criteria-&gt;condition.' and newreferenceno LIKE &#092;'%'.&#036;_POST['refno'].'%&#092;'';


        }





    }


    &#036;dataProvider=new CActiveDataProvider('Onlinecolortolerance', array(


        'criteria'=&gt;&#036;criteria,


        'pagination'=&gt;array(


            #'pageSize'=&gt;Yii::app()-&gt;controller-&gt;module-&gt;user_page_size,


        ),


    ));








    &#036;model = new onlinecolortolerance;


    &#036;main = &#036;model::model()-&gt;findAll();





    &#036;this-&gt;render('main', array(


            'dataProvider'=&gt;&#036;dataProvider,


            'model'=&gt;&#036;model,


            'mainview'=&gt;&#036;main,


        )


    );








}

}

please help me how my search work thanks a lot (^_^)

Don’t use <style> tags in Yii. Use Yii::app()->clientScript->registerCss instead

http://www.yiiframework.com/wiki/800/how-to-register-scripts-and-css/

You should also use the "Insert code snippet" of the forum editor to highlight your code and make it more readable.

xmatzx01 why not to use with the widget (for example gridview)