重定向到textarea点击登录页面?

时间:2016-08-23 10:45:00

标签: php controller yii2

我正在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,
    ]);
}   
像我说的那样控制器只允许登录用户插入评论。

1 个答案:

答案 0 :(得分:1)

您需要使用JavaScript和:

  1. 在textarea上添加onClick事件
  2. 检查您的用户是否已登录,否则使用window.location = "http://www.yoururl.com";重定向