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">
<select class="form-control" name="lsdstatus">
<option value="">LSD Status</option>
<?php
$lsdstat=lsdstatus::model()->findAll();
foreach($lsdstat as $lsdstat){
echo '<option value='.$lsdstat->id.'>'.$lsdstat->name.'</option>';
}
?></select>
</div>
<div class="xxx">
<select class="form-control" name="jobstatus">
<option value="">Job Status</option>
<?php
$jobstat=jobstatus::model()->findAll();
foreach( $jobstat as $jobstat){
echo '<option value='.$jobstat->id.'>'.$jobstat->name.'</option>';
}
?></select>
</div>
<div class="xxx">
<select class="form-control" name="customername">
<option value="">Customer Name</option>
<?php
$cname=customer::model()->findAll();
foreach( $cname as $cname){
echo '<option value='.$cname->id.'>'.$cname->name.'</option>';
}
?></select>
<br />
</div>
<div class="xxx">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Search' : 'Save',array('class'=>'btn btn-primary','name'=>'search')); ?>
<?php echo CHtml::submitButton($model->isNewRecord ? 'Clear Search' : 'Clear Search',array('class'=>'btn btn-primary','name'=>'clearsearch')); ?>
</div>
<div class="tabledata">
<table class="table table-hover table-bordered">
<tr>
<thead>
<!-- <th>#</th>-->
<th>Reference No.</th>
<th>Item Code</th>
<!--<th>Old Reference No.</th>-->
<th>Customer Name</th>
<th>Product Code</th>
<th>Product description</th>
<th>Jo No</th>
<th>LSD Status</th>
<th></th>
</thead>
</tr>
<tbody>
<br />
<?php
foreach($mainview as $main) {/<td>’ . $main[‘id’]. ’ </td><td>’ . $main[‘oldreferenceno’]. ’ </td>/
// $main = onlinecolortolerance::model()->findByAttributes(array(‘id’ => $main->id));
echo ' <tr>
<td>' . $main['newreferenceno']. ' </td>
<td>' . $main['itemcode']. ' </td>
<td >' . $main['customername']. ' </td>
<td>' . $main['productcode']. ' </td>
<td>' . $main['productdescription']. ' </td>
<td>' . $main['jono']. ' </td>
<td>' . $main['lsdstatus']. ' </td>
<td nowrap>'.CHtml::link('Select',array('site/index'),array('class'=>'btn btn-primary')).'</td>
</tr>';
}?>
</tbody>
</table>
</div>
[size="6"]Controler[/size]
<?php
class OnlinecolortoleranceController extends Controller
{
public function actionIndex()
{
$this->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'=>'path.to.ActionClass',
'action2'=>array(
'class'=>'path.to.AnotherActionClass',
'propertyName'=>'propertyValue',
),
);
}
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','Main'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update','main'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete','main'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
public function actionAdmin()
{
$model=new Issue('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Issue']))
$model->attributes=$_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
$model->project_id = $this->_project->id;
$this->render('admin',array(
'model'=>$model,
));
}
public function actionMain()
{
$criteria= new CDbCriteria;
if(isset($_POST['search'])){
$criteria->condition= 'id!=0';
if($_POST['refno']!=null){
$criteria->condition= $criteria->condition.' and newreferenceno LIKE \'%'.$_POST['refno'].'%\'';
}
}
$dataProvider=new CActiveDataProvider('Onlinecolortolerance', array(
'criteria'=>$criteria,
'pagination'=>array(
#'pageSize'=>Yii::app()->controller->module->user_page_size,
),
));
$model = new onlinecolortolerance;
$main = $model::model()->findAll();
$this->render('main', array(
'dataProvider'=>$dataProvider,
'model'=>$model,
'mainview'=>$main,
)
);
}
}
please help me how my search work thanks a lot ()