I am creating a checkbox list, and I could like to calculate the price when the user checks on the box.
I have create a checkboxlist in the view part
<?php echo CHtml::checkboxList('cblist_addons','',
CHtml::listData(Addon::model()->findAll("car_type_id=1"),'id','concatenedLabel'),
array('separator'=>'','template'=>'{label}{input}','class'=>'cblist_addons'));?>
This one works fine. But in the controller part, I would like to generate a string like [a, b, c]
$str_addons = "";
if(isset($_POST['cblist_addons']) && !empty($_POST['cblist_addons']) ) {
foreach($_POST['cblist_addons'] as $addon) {
if ($addon.checked){
$str_addons .= $addon.val(). ', ';
}}
$str_addons = substr($str_addons, 0, -2); //to del the last comma
}
$criteria = new CDbCriteria();
$criteria->select = 'price';
if ($str_addons != ''){
$criteria->condition = 'id in (:cblist_addons)';
$criteria->params = array(':cblist_addons'=> $str_addons) ;
}
else{
$criteria->condition = 'id in (1,2,3,4) '; //the path go into this else part with no error
}
$model_addons = Addon::model()-> findAll ($criteria);
Seems I am fail in getting the object from view part. I am newbie in yii and php I have just tried to solve this problem in few days so I hope anyone can help me.
Let me explain more. I am creating a checkboxlist and when I press the button or check the checkbox, an ajax function will be called and the price will be calculated and display in the view part.