Hi,
after reading this:
http://www.yiiframework.com/wiki/19/
and searching in the forum I not found any solution for my problem.
I created a _form like this:
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'restaurant-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="help-block">Fields with <span class="required">*</span> are required.</p>
<?php echo CHtml::errorSummary($model,$tags); ?>
<div class="btn-toolbar">
<?php echo $form->labelEx($model,'country'); ?>
<?php echo $form->dropDownList($model,'country', CHtml::listData(Country::model()->findAll(), 'country_id', 'short_name'),array(
'empty'=>'Select Country',
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('restaurant/dynamicstates'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'success' => 'js:function(data) {
var parsed = $.parseJSON(data);
var o = $("#state");
o.empty();
$.each(parsed.states, function(){
o.append($("<option value=\'"+this.id+"\'>"+this.name+"</option>"));
});
$("#Restaurant_tel").val("(+"+parsed.prefix+")"); }',
'update'=>'#state', //selector to update
'data'=>array('country'=>'js:this.value'),
//leave out the data key to pass all form values through
))); ?>
</div>
[b] <?php echo $form->checkBoxListInlineRow($tags, 'idcuisintype',CHtml::listData(CuisinesTypes::model()->findAll(),'id','word')); ?>
[/b]
<div class="btn-toolbar">
<?php echo $form->labelEx($model,'state'); ?>
<?php echo CHtml::dropDownList('state','', array('empty'=>'Only if Country is US')); ?>
</div>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? 'Create' : 'Save',
)); ?>
</div>
<?php $this->endWidget(); ?>
the line in bold is the one that belong to $tags model.
In the actionCreate in the controller i wrote the following code:
$model=new Restaurant;
$tags=new RestCuisineTypeRel;
if(isset($_POST['Restaurant'],$_POST['RestCuisineTypeRel']))
{
$model->attributes=$_POST['Restaurant'];
$tags->attributes=$_POST['RestCuisineTypeRel'];
$country = Country::model()->findByPk($model->country);
if($model->validate() & $tags->validate()) {
$model->save(false);
$tags->save(false);
$this->redirect(array('view','id'=>$model->idrest));
}
}
$this->render('create',array(
'model'=>$model,
'tags' => $tags,
));
But after I submit the form it got this error:
[b]Object of class RestCuisineTypeRel could not be converted to string
[/b]
RestCuisineTypeRel is the model of $tags variable
can you please help me, i’m going crazy!