douzhao7634 2015-12-26 11:15
浏览 53
已采纳

在actionView yii2中从url获取id值的问题

I'm trying to pass the id from the URL using the get method, but when I try to get it with actionView in the controllers. When I try to echo the id to check, if it passes the correct id from the URL. the value is always my controller ID. here is my view which passes the id when I click on delete button :

<?php
  foreach($twit as $twits){
?>


<header class="text-right">
    <div class="comment-user"> سبحان باقری <i class="fa fa-user"></i></div>
    <time class="comment-date" datetime="16-12-2014 01:05"> Dec 16, 2014 <i class="fa fa-clock-o"></i></time>
</header>
<div class="panel panel-default arrow left">

  <div class="panel-body">

    <?= Html::a('Delete','?r=twit/delete-twit&id='.$twits['id'],['class' => 'pull-left btn btn-danger btn-sm']); ?>
    <?= Html::a('Update','#&id='.$twits['id'],['class' => 'pull-left btn btn-primary btn-sm']); ?>


      <div class="comment-post">
          <p style="text-align:right;font-weight:bold;">
              <?php echo $twits['twit']; ?>
          </p>
      </div>
      <p class="text-right"><a href="#" class="btn btn-success btn-sm"><i class="fa fa-reply"></i> reply</a></p>
  </div>
</div>

<?php  } ?>

and here is my controller actionView which i want to get the id value and then send it to actionDeleteTwit :

public function actionView($id = null)
{
    echo $id;
    die();
}

and here is my actionDeleteTwit which i don't know how to pass the id value to it :

public function actionDeleteTwit()
{

    if(Yii::$app->request->get() && Yii::$app->request->get('id')){
        $id = Yii::$app->request->get('id');
        Twit::deleteTwit($id);
        \yii::$app->response->redirect('?r=twit/index',301)->send();
    }
}

(I don't want to use the Yii::$app->request->get('id') and I'm trying to use the actionView instead )

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 有人知道怎么将vsi格式的图片文件,转换为svs格式的文件吗
      • ¥15 历史模拟法计算var实验报告
      • ¥15 白鲸算法优化K值的VMD分解出错
      • ¥20 写一个基于52单片机用hc-05蓝牙模块控制28BYJ-48步进电机进行旋转,在手机蓝牙串口输入1019电机转半圈,输入2038电机转一圈,输入0复位的代码吗
      • ¥15 求51单片机8位数码管计时器程序
      • ¥20 matlab识别螺母边缘
      • ¥15 python 6x6游戏加登录、记录系统
      • ¥100 基于做一个模拟智慧路灯
      • ¥15 ME21N 创建采购成功并且生成采购订单号,但显示“快件文档更新已取消”,SM13看错误提示为如下截图:
      • ¥30 android 集成fmod实现变声功能中遇到的问题