Answer the question
In order to leave comments, you need to log in
Why does it always output null for input?
I solved the issue by doing this by default in the model so that the user id is displayed, but for the sake of interest, for the first time I encountered such a problem that it constantly displays null for me. even if required still fails validation.
class Zakaz extends ActiveRecord
{
const SCENARIO_DEFAULT = 'default';
public function scenarios()
{
return [
self::SCENARIO_DECLINED => ['declined', 'required'],
self::SCENARIO_DEFAULT => ['id_shop', ...],
];
public function rules()
{
return [
[['srok', 'number', 'description', 'phone', 'id_client', 'id_shop'], 'required', 'on' => self::SCENARIO_DEFAULT],
['declined', 'required', 'message' => 'Введите причину отказа', 'on'=> self::SCENARIO_DECLINED],
[['id_shop', ...], 'integer'],
// ['id_shop', 'default', 'value' => Yii::$app->user->getId()],
...
];
}
}
<?= $form->field($model, 'id_shop')->textInput(['value' => Yii::$app->user->id]) ?>
Answer the question
In order to leave comments, you need to log in
Why does it always output null for input
Yii::$app->user->id
and it is null, there is a user not registered. If there is no user, what id do you expect to see? Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question