我正在yii2中发表评论表格并且它运作良好但我还希望评论textarea重定向未登录到登录页面的用户。我想要的是点击teaxtarea注释用户被重定向到登录页面,登录后返回允许用户发表评论.. 我知道我是否放了一个像
这样的按钮 <?= Html::a('up', ['comment'], [ 'class' => 'btn btn-primary' ]) ?>
并将其仅放在
中这是我的表格
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($comment, 'user_comment')->textarea(['rows' => 4,'columns' => 12]) ?>
<br>
<?= Html::submitButton('Save', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
<?php ActiveForm::end(); ?>
这是我的控制器
public function actionBlog()
{
$comment= new Comment();
$comment->byy=Yii::$app->user->identity->email;
if ($comment->load(Yii::$app->request->post()) ) {
$comment->load($_POST);
$comment->save();
return $this->refresh();
}
return $this->render('blog',[
'comment' => $comment,
]);
}
像我说的那样控制器只允许登录用户插入评论。
答案 0 :(得分:1)
您需要使用JavaScript
和:
onClick
事件window.location = "http://www.yoururl.com";
重定向