$('span').click(function(){
$(this).addClass......
})
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'console\controllers',
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'controllerMap' => [
'fixture' => [
'class' => 'yii\console\controllers\FixtureController',
'namespace' => 'common\fixtures',
],
],
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
],
'params' => $params,
];
public function actionCreate() {
$model = new SignupHandForm();
// Ajax-валидация
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
// Сохранение
if ($model->load(Yii::$app->request->post())) {
if ($model->validate()) {
return $model->signup();
} else { return null; }
}
public function rules()
{
return [
['email', 'required'],
['email', 'email'],
['email', 'unique', 'targetClass' => User::className(), 'message' => 'Эта почта уже зарегистрирована'],
['fio', 'trim'],
['fio', 'required'],
['fio', 'string', 'min' => 1,],
['phone_mobile', 'trim'],
['phone_mobile', 'required'],
['phone_mobile', 'string', 'min' => 11,],
['position_id', 'required'],
['position_id', 'exist', 'targetClass' => Positions::className(), 'targetAttribute' => 'id'],
['pay_type', 'required'],
['pay_type', 'exist', 'targetClass' => PayTypes::className(), 'targetAttribute' => 'id'],
['pay_account', 'trim'],
['pay_account', 'required'],
['pay_account', 'string',],
];
}
public function signup()
{
if (!$this->validate()) {
return null;
}
$user = new User();
$user->email = $this->email;
$user->setPassword('123456');
$user->generateAuthKey();
return $user->save() ? $user : null;
}
<?php
namespace common\models;
use Yii;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "positions".
*
* @property integer $id
* @property string $title
*/
class Positions extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'positions';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['title'], 'string', 'max' => 16],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Должность',
];
}
/**
* Список всех должностей массивом
* @return array
*/
public function getAllAsArray() {
return ArrayHelper::map(self::find()->all(), 'id', 'title');
}
}
[
'attribute' => 'position_id',
'value' => 'position.title',
'label' => 'Должность',
//'filterType' => GridView::FILTER_SELECT2,
'filter' => Positions::getAllAsArray(),
],