Answer the question
In order to leave comments, you need to log in
Working with the form, automatic substitution, how to do it?
I have registered on the site, how can I insert an automatic value in comment_author so that the user does not write the name ?
<?php $form->field($model, 'comment_author')?>
Answer the question
In order to leave comments, you need to log in
$model->comment_author = 111;
<?php $form->field($model, 'comment_author')?>
In the controller action:
public function actionComment()
{
..............
...............
if (!Yii::$app->user->isGuest) {
$model->comment_author = Yii::$app->user->identity->username;
}
return $this->render('comment', ['model' => $model]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question