0
나는 Yii를 처음 사용하는데 두 개의 테이블이 있습니다. master_customer, master_client. 클라이언트 모델에서 검색 상자가있는보기에서 검색 상자에 몇 글자를 입력하면 자동으로 데이터를 가져와 master_customers (예 : Google 제안)의 결과를 제공해야합니다. master_customer와 클라이언트 모델에서 관계를 만들었습니다. 코드를 도와주세요. 미리 감사드립니다검색에서 AJAX 유효성 확인
컨트롤러 액션 :
public function actionIndex()
{
$criteria = new CDbCriteria();
if(isset($_GET['q']))
{
$q = "%".$_GET['q']."%";
$criteria->condition = 'cust_name='.$q;
$arrTier3 = MasterCustomers::model()->findAll($criteria);
//$criteria->compare(MasterCustomers::model()->cust_name,$q, true);
//$criteria->compare('$data->customers->cust_name', $q, true, 'OR');
print_r($arrTier3);
die();
}
$dataProvider=new CActiveDataProvider('Host', array('criteria'=>$criteria));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
보기 : 각 키 누름에 검색하고의 GridView를 업데이트 구글 같은 검색을해야하는 경우
<!--Content-->
<div id="content">
<div style="padding: 10px;">
<a href="<?php echo $this->createUrl('/Controller/create');?>" title="Create New Host" class="btn btn-primary circle_ok" style="text-decoration: none;" >Add New Host to Customer</a>
<div style="float:right">
<?php
echo CHtml::link('Upload Customer CSV', array('/Controller/uploadCustomers'), array(
'onclick'=>'return hs.htmlExpand(this, { objectType: "iframe", wrapperClassName: "full-size", align: "center" })',
'class'=>'btn btn-primary',
'id'=>'upload_link',
));
?>
</div>
</div>
<h3><?php echo $title; ?></h3>
<div class="innerLR">
<div class="row-fluid">
<?php
$obj=$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
//'afterAjaxUpdate'=>'\'changeTRColor()\'',
//'itemView'=>'_view',
'columns'=>array(
array( // display 'create_time' using an expression
'name'=>'name',
'value'=>'$data->host_name',
),
array(
'name'=>'serviceId',
'value'=>'$data->host_serviceid',
),
array(
'name'=>'customer',
'value'=>'$data->customers->cust_name',
),
array(
'class'=>'CButtonColumn',
'template'=>'{delete}{update}',)
),
));
?>
<form method="get">
<input type="search" placeholder="search" name="q" value="<?=isset($_GET['q']) ? CHtml::encode($_GET['q']) : '' ; ?>" />
<input type="submit" value="search" />
</form>
</div>
<div class="separator bottom"></div>
</div>
</div>
<!-- // Content END -->
<div class="clearfix"></div>
<!-- // Sidebar menu & content wrapper END -->
<div id="footer" class="hidden-print">
<?php $this->renderPartial('application.views.layouts._footer_inc'); ?>
</div>
무엇을 시도 했습니까? 보여 주다 –