'urlCreator' => function($action, $model, $key, $index) {
return Url::to([__DIR__.'/'.$action,'id'=>$key]);
},
Путь стоит правильный, но ошибку выдает 404 <?php
namespace backend\models;
use backend\models\setting\City;
use backend\models\setting\District;
use Yii;
/**
* This is the model class for table "judge".
*
* @property integer $id
* @property string $last_name
* @property string $name
* @property string $middle_name
* @property string $date_birthday
* @property integer $id_district
* @property integer $id_city
* @property string $phone
* @property string $email
* @property integer $status
*
* @property Appointment[] $appointments
* @property City $idCity
* @property District $idDistrict
* @property JudgeComitet[] $judgeComitets
*/
class Judge extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'judge';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['last_name', 'name', 'id_district', 'id_city', 'email', 'status'], 'required'],
[['id_district', 'id_city', 'status'], 'integer'],
[['last_name', 'name', 'middle_name', 'phone', 'email'], 'string', 'max' => 190],
[['last_name', 'name', 'middle_name'], 'unique', 'targetClass' => '\backend\models\Judge', 'targetAttribute' => ['last_name', 'name', 'middle_name'], 'message' => 'Пользователь с такой ФИО уже существует!'],
[['date_birthday'], 'string', 'max' => 30],
[['email'], 'unique'],
[['last_name', 'name'], 'string', 'min' => 2],
[['phone'], 'unique'],
[['phone'], 'string', 'min' => 6, 'max' => 11],
[['id_city'], 'exist', 'skipOnError' => true, 'targetClass' => City::className(), 'targetAttribute' => ['id_city' => 'id']],
[['id_district'], 'exist', 'skipOnError' => true, 'targetClass' => District::className(), 'targetAttribute' => ['id_district' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('backend', 'ID'),
'last_name' => Yii::t('backend', 'Last Name'),
'name' => Yii::t('backend', 'Name'),
'middle_name' => Yii::t('backend', 'Middle Name'),
'date_birthday' => Yii::t('backend', 'Date Birthday'),
'id_district' => Yii::t('backend', 'Id District'),
'id_city' => Yii::t('backend', 'Id City'),
'phone' => Yii::t('backend', 'Phone'),
'email' => Yii::t('backend', 'Email'),
'status' => Yii::t('backend', 'Status'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAppointments()
{
return $this->hasMany(Appointment::className(), ['id_judge' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdCity()
{
return $this->hasOne(City::className(), ['id' => 'id_city']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdDistrict()
{
return $this->hasOne(District::className(), ['id' => 'id_district']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getJudgeComitets()
{
return $this->hasMany(JudgeComitet::className(), ['judge_id' => 'id']);
}
public function getStatusList()
{
return [
'0'=>'Не активен',
'1'=>'Активен',
];
}
public function getStatusName()
{
$list = self::getStatusList();
return $list[$this->status];
}
public function getFullName()
{
return $this->last_name.' '.$this->name.' '.$this->middle_name;
}
}
<?php
namespace backend\models;
use backend\models\setting\Category;
use backend\models\setting\Comitet;
use Yii;
/**
* This is the model class for table "judge_comitet".
*
* @property integer $judge_id
* @property integer $comitet_id
* @property integer $category_id
*
* @property Category $category
* @property Comitet $comitet
* @property Judge $judge
*/
class JudgeComitet extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'judge_comitet';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['judge_id', 'comitet_id', 'category_id'], 'required'],
[['judge_id', 'comitet_id', 'category_id'], 'integer'],
[['comitet_id'], 'unique'],
[['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'id']],
[['comitet_id'], 'exist', 'skipOnError' => true, 'targetClass' => Comitet::className(), 'targetAttribute' => ['comitet_id' => 'id']],
[['judge_id'], 'exist', 'skipOnError' => true, 'targetClass' => Judge::className(), 'targetAttribute' => ['judge_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'judge_id' => Yii::t('backend', 'Judge ID'),
'comitet_id' => Yii::t('backend', 'Comitet ID'),
'category_id' => Yii::t('backend', 'Category ID'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCategory()
{
return $this->hasOne(Category::className(), ['id' => 'category_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getComitet()
{
return $this->hasOne(Comitet::className(), ['id' => 'comitet_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getJudge()
{
return $this->hasOne(Judge::className(), ['id' => 'judge_id']);
}
public function getFullName()
{
return $this->judge->last_name.' '.$this->judge->name.' '.$this->judge->middle_name;
}
}
<?php
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use backend\models\JudgeComitet;
/* @var $this yii\web\View */
/* @var $model backend\models\JudgeComitet */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="judge-comitet-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'judge_id')->widget(Select2::classname(), [
'data' => ArrayHelper::map(\backend\models\Judge::find()->where(['status'=>1])->asArray()->all(), 'id', 'fullName'),
'language' => 'ru',
'options' => ['placeholder' => 'Выберите судью...'],
'pluginOptions' => [
'allowClear' => false
],
]);?>
<?= $form->field($model, 'comitet_id')->widget(Select2::classname(), [
'data' => ArrayHelper::map(\backend\models\setting\Comitet::find()->asArray()->all(), 'id', 'name'),
'language' => 'ru',
'options' => ['placeholder' => 'Выберите комитет...'],
'pluginOptions' => [
'allowClear' => false
],
]);?>
<?= $form->field($model, 'category_id')->widget(Select2::classname(), [
'data' => ArrayHelper::map(\backend\models\setting\Category::find()->asArray()->all(), 'id', 'name'),
'language' => 'ru',
'options' => ['placeholder' => 'Выберите категорию...'],
'pluginOptions' => [
'allowClear' => false
],
]);?>
<?php if (!Yii::$app->request->isAjax){ ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php } ?>
<?php ActiveForm::end(); ?>
</div>
public function getFullName()
{
return $this->last_name.' '.$this->name.' '.$this->middle_name;
}
public function getFullName()
{
return $this->judge->last_name.' '.$this->judge->name.' '.$this->judge->middle_name;
}
public function getList()
{
///Запрос к базе данных
return [
'last_name'=>'Ворожцов',
'name'=>'Максим',
..........
];
}
формировать запросы к базе данных в View - это говнокод. Поэтому лучше вынесите их куда-нибудь в другое место