I’m trying to develop a dynamic model. The view has a multiple select listbox and I can’t seem to extract the selected items in the controller. I’m assuming I haven’t setup my model class properly.
/**
* This is the model class for a DynamicModel
*
* @property int $StatusId
* @property int $ReportId
* @property string $StartDt
* @property string $EndDt
* @property EmployeeId[] $EmployeeId
*
*
*/
// class Reporting extends \yii\db\ActiveRecord
class Reporting extends Model
{
public $EmployeeId;
public $StatusId;
public $StartDt;
public $EndDt;
public $ReportId;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['StartDt', 'EndDt', 'ReportId'], 'required'],
[['ReportId'], 'integer'],
[['EmployeeId, StatusId'], 'safe'], //Optional
[['StartDt', 'EndDt'], 'date', 'format' => 'php:Y-m-d'],
];
}
In my view I have
echo $form->field(
$model,
'EmployeeId',
[
'inputOptions' => ['tabIndex' => '-1'],
'horizontalCssClasses' => [
'wrapper' => 'col-md-8',
],
]
)->listBox(
ArrayHelper::map(
Employees::find()
->orderBy([
'FirstName' => SORT_ASC,
'LastName' => SORT_ASC
])
->all(),
'id',
function ($model) {
return $model['FirstName'] . ' ' . $model['LastName'];
}
),
[
'multiple' => 'true',
'size' => 8,
]
);
And in my controller I was trying to do something like
$dispatcherUserIds = rtrim(implode(',', $model->DispatcherId), ',');