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 http://www.yiiframework.com/extension/echmultiselect/ extension. Maybe you have better way… I want something like list of checkboxes with users, select and send. I thought about using http://www.yiiframework.com/extension/multimodelform/ 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 ?
form:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'adress-form',
'enableAjaxValidation'=>false,
)); ?>
<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>
<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>
<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>
<!--
<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">
<?php
$data= CHtml::listData(User::model()->findAll(), 'id', 'firstname');
$this->widget('ext.EchMultiSelect.EchMultiSelect', array(
'model' => $model,
'dropDownAttribute' => 'adress_user_id',
'data' => $data,
'dropDownHtmlOptions'=> array(
'style'=>'width:378px;',
),
)); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
model:
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'),
);
}
Controller:
public function actionCreate()
{
$model=new Adress;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Adress']))
{
$model->attributes=$_POST['Adress'];
if($model->adress_user_id!=='')
$model->adres_users_id=implode(',',$_POST['Adress']['adress_user_id']);
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$model->adress_user_id=explode(',', $model->adress_user_id);
$this->render('create',array(
'model'=>$model,
));
}
public function actionIndex()
{
$current_id = Yii::app()->user->getId();
$dataProvider=new CActiveDataProvider('Adress', array(
'criteria'=>array(
'condition'=>'adress_user_id='.$current_id,
'order'=>'create_date DESC',
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
implode/explode will not work for my id INT column, how should I do it ?