Answer the question
In order to leave comments, you need to log in
How to replace such code?
Hello! How can we replace such usages and move them from the controller to the model?
....
public function actionCreate()
{
$event_id = Registration::getEventId();//Обращение к модулю. В нем получаем event_id
$model = new RegBattle(['event_id'=>$event_id])
///другое...
}
....
public function actionCreate()
....
public function actionCreate($event_id)
{
$model = new RegBattle(['event_id'=>$event_id]) //event_id получаем из get запроса
///другое...
}
....
/**
* Инициализация модели
*/
public function init()
{
parent::init();
if ($this->isNewRecord){
$this->event_id = Registration::getEventId();
$this->number = self::setNumber();
}
}
$this->number = self::setNumber();
automatically initialize the value with the last number in the input field/**
* Добавить номер
* @return mixed
*/
public static function setNumber()
{
$event_id = Registration::getEventId();
return self::find()->where(['event_id' => $event_id])->max('number') + 1;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question