public function actionSave() { $model = new OrderSaver(['modelClass' => Company::className()]); if ($model->load(\Yii::$app->request->post())) { if ($model->validate()) { $model->save(); \Yii::$app->session->setFlash('success', 'Порядок отображения успешно сохранен.'); } else { \Yii::$app->session->setFlash('danger', 'Порядок сохранить не удалось.'); } } return $this->render('save', ['model' => $model]); }
/** * @return \yii\db\ActiveQuery */ public function getCompany() { return $this->hasOne(Company::className(), ['id' => 'company_id']); }
<div class="vks-room-form col-md-6"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name'); ?> <?php echo $form->field($model, 'shortName'); ?> <?php echo $form->field($model, 'companyId')->widget(Select2::className(), ['data' => ViewHelper::items(Company::className(), '_id', 'name')]); ?> <?php echo $form->field($model, 'ahuConfirmation')->checkbox(); ?> <?php echo $form->field($model, 'confirmPersonId')->widget(Select2::className(), ['data' => $model::confirmPersonList(), 'options' => ['placeholder' => 'Выберите пользователя ...'], 'pluginOptions' => ['allowClear' => true]]); ?> <?php echo $form->field($model, 'supportEmailsInput'); ?> <?php
/** * @return array */ public function rules() { return [[['name', 'shortName'], 'required'], ['companyId', 'exist', 'targetClass' => Company::className(), 'targetAttribute' => '_id'], ['ahuConfirmation', 'boolean'], ['ahuConfirmation', 'filter', 'filter' => function ($value) { return boolval($value); }], ['confirmPersonId', 'exist', 'targetClass' => User::className(), 'targetAttribute' => '_id'], ['supportEmailsInput', function ($attribute) { if ($this->{$attribute} === "") { $this->supportEmails = []; return; } $value = explode(';', trim($this->{$attribute}, ';')); $validator = new EachValidator(['rule' => ['email']]); if ($validator->validate($value)) { $this->supportEmails = $value; } else { $this->addError($attribute, "Неверный формат"); } }, 'skipOnEmpty' => false], ['ipAddress', 'match', 'pattern' => '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/'], [['phone', 'contact', 'model', 'gatekeeperNumber', 'note'], 'safe'], [['companyId', 'confirmPersonId'], MongoIdValidator::className(), 'forceFormat' => 'object']]; }
<?php use yii\helpers\Html; use yii\grid\GridView; use common\models\Company; use common\components\helpers\ViewHelper; /* @var $this yii\web\View */ /* @var $model \app\models\VksParticipantSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Переговорные комнаты'; ?> <div class="vks-room-index"> <div class="page-header"><h2><?php echo $this->title; ?> </h2></div> <?php echo Html::a('<span class="glyphicon glyphicon-plus"></span>', ['create'], ['class' => 'btn btn-sm btn-default']); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $model, 'columns' => ['shortName', ['filter' => ViewHelper::items(Company::className(), '_id', 'name'), 'attribute' => 'companyId', 'value' => 'company.name'], 'ipAddress', 'note:ntext', ['class' => 'yii\\grid\\ActionColumn', 'contentOptions' => ['width' => '70px;']]]]); ?> </div>
public function actions() { return ['index' => ['class' => SearchAction::className(), 'modelClass' => VksCompanySearch::className()], 'create' => ['class' => CreateAction::className(), 'modelClass' => Company::className()], 'update' => ['class' => UpdateAction::className(), 'modelClass' => Company::className()], 'delete' => ['class' => DeleteAction::className(), 'modelClass' => Company::className()]]; }