Insert Many Id

Hi, I’m trying to create a communication system in my app. I have form with title,content, signature and adress_user_id that will read msg. Now I have problem cuz i don’t know what to do if I want to choose many users.

I want to use extension. Maybe you have better way… I want something like list of checkboxes with users, select and send. I thought about using but it creates needed fields only for 1 user. So 10 msg is 10*3 needed fields. (pointless)

Now I only have possibility of choosing 1 user, how should I do this ?


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(



)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">

		<?php echo $form->labelEx($model,'title'); ?>

		<?php echo $form->textField($model,'title',array('size'=>45,'maxlength'=>45)); ?>

		<?php echo $form->error($model,'title'); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'content'); ?>

		<?php echo $form->textArea($model,'content',array('rows'=>6, 'cols'=>50)); ?>

		<?php echo $form->error($model,'content'); ?>



	<div class="row">

		<?php echo $form->labelEx($model,'signature'); ?>

		<?php echo $form->textField($model,'signature',array('size'=>45,'maxlength'=>45)); ?>

		<?php echo $form->error($model,'signature'); ?>



	<div class="row">

		<?php //echo $form->labelEx($model,'adress_user_id'); ?>

		<?php //echo $form->dropDownList($model,'adress_user_id',$model->getAllUser()); ?>

		<?php //echo $form->error($model,'adress_user_id'); ?>

	</div> -->

        <div class="row">


        $data= CHtml::listData(User::model()->findAll(), 'id', 'firstname');

        $this->widget('ext.EchMultiSelect.EchMultiSelect', array(

            'model' => $model,

            'dropDownAttribute' => 'adress_user_id',     

            'data' => $data,

            'dropDownHtmlOptions'=> array(



        )); ?>


	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>


<?php $this->endWidget(); ?>

</div><!-- form -->


public function relations()


		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'adressUser' => array(self::BELONGS_TO, 'User', 'adress_user_id'),




public function actionCreate()


		$model=new Adress;

		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);









                $model->adress_user_id=explode(',', $model->adress_user_id);





public function actionIndex()


                $current_id = Yii::app()->user->getId();

		$dataProvider=new CActiveDataProvider('Adress', array(



                        'order'=>'create_date DESC',







implode/explode will not work for my id INT column, how should I do it ?

Still no idea ? I was looking for it for whole day but still nothing ;/


serialize your array while inserting into the db

$value =serialize($_POST['Adress']['adress_user_id'])

Store the this in db

and to retreive from db

 unserialize($value ) // Value from the db , this will return array.


Yea I think that I don’t know where should i put it, or maybe whole idea is wrong. It should be in model in beforeSave function or in controller actionCreate ??

I have only field with user_id(INT) from related model, maybe I should create another field(VARCHAR) to store all this Id and then retreive it and somehow use them to point proper column ? Will it work ?

In general you need to create a method in your Controller class and should call it to save this data from your create action.Since if you are thinking to do this code in beforeSave then you can face some issue.So, in a ideal way should create a Private Method in Controller class. Or better then this …You can define a method in a Behavior class and attach that behavior to your controller class.