hi friends…
i use the search feature using the ajex filter…
here i have 3 table
1-> tbl_product_index(product_id,master_Key,product_name)
2-> tbl_master_index(master_key,brand)
3-> tbl_pricing(product_id,price,mobile_type)
relation create by the gii…
here is my code…
in productindexcontroller:
actionindex is
public function actionIndex()
{
$model = new ProductIndex();
$master_key = (isset($_GET['ProductIndex']['master_key'])) ? $_GET['ProductIndex']['master_key'] : array();
$product_id = (isset($_GET['ProductIndex']['product_id'])) ? $_GET['ProductIndex']['product_id'] : array();
$result = array_merge((array)$master_key, (array)$product_id);
CVarDumper::dump($master_key);
CVarDumper::dump($product_id);
$criteria = new CDbCriteria();
//take the other table column
$criteria->with = 'pricing';
$criteria->together = true;
if( count( $master_key ) > 0 )
{
$criteria->addInCondition( 'master_key', $master_key );
}
if( count( $product_id ) > 0 )
{
$criteria->addInCondition( 'pricing.mobile_type', $product_id );
}
$dataProvider = new CActiveDataProvider('ProductIndex',
array('criteria'=>$criteria));
$this->render('index',array(
'dataProvider'=>$dataProvider,
'model'=>$model,
));
}
and in view is
index.php:
<h4>Brand:</h4>
<?php
Yii::app()->clientScript->registerScript('search',
"var ajaxUpdateTimeout;
var ajaxRequest;
$('.masterindexFilter').change(function(){
master_key = $('.masterindexFilter').serialize();
$.fn.yiiListView.update(
'ajaxListView',
{
url: '" . CController::createUrl('productindex/index') . "',
data: master_key,
}
);
});
$('.pricingFilter').change(function(){
product_id = $('.pricingFilter').serialize();
$.fn.yiiListView.update(
'ajaxListView',
{
url: '" . CController::createUrl('productindex/index') . "',
data: product_id,
}
);
});
$('input#productindex').keyup(function(){
ajaxRequest = $(this).serialize();
clearTimeout(ajaxUpdateTimeout);
ajaxUpdateTimeout = setTimeout(function () {
$.fn.yiiListView.update(
// this is the id of the CListView
'ajaxListView',
{data: ajaxRequest}
)
},
// this is the delay
300);
});"
);
?>
<?php
echo CHtml::activeCheckboxList(
$model, 'master_key',
CHtml::listData(MasterIndex::model()->findAll(), 'master_key', 'brand'),
array('template'=>'<li>{input} {label}</li>', 'class'=>'masterIndexFilter',)
);
?>
<h4>OS:</h4>
<?php
echo CHtml::activeCheckBoxList($model,'product_id',
CHtml::listData(Pricing::model()->findAll(), 'mobile_type', 'mobile_type'),
array( 'template'=>'<li>{input} {label}</li>', 'class'=>'pricingFilter',));
?>
<?php
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_new',
'id'=>'ajaxListView',
));
?>
here i am able to search brand and mobile_type individually but not together because when i select brand checkbox then it select brand and store the value in $master_key.and when i select os(mobile_type) checkbox that time store the value in $product_id and $master_key is null.
i want to store the value in both the variable together one after other and search both together.
also i want to know that
$master_key = (isset($_GET['ProductIndex']['master_key'])) ? $_GET['ProductIndex']['master_key'] : array();
$product_id = (isset($_GET['ProductIndex']['product_id'])) ? $_GET['ProductIndex']['product_id'] : array();
is any way to write this code in one variable in place of two variable?
any help pls.
thanks in advance.