当从控制器向视图页面渲染具有两位数的数组时,该数组仅显示第一个单个数字值
视图/ view1.php
<a class="btn btn-success" href="index.php?r=followusers/follow&id=<?= $follower1, $followed1; ?>" >Follow</a>
控制器
public function actionFollow($id)
{
$model = Followusers::findOne($id);
return $this->render('follow', [
'model' => $model, 'id' => $id,
]);
视图/ follow.php
Yii::$app->db->createCommand()
->insert('followusers', [
'follower' => $id[0],
'followed' => $id[1],
])->execute();
Yii::$app->response->redirect(['user/view1','id' => $id[1]]);
}
当$ follower1或$ follow1被赋值为10时,只需点击跟随按钮即可获得1
为什么它发生在我的代码中有任何错误
提前谢谢
答案 0 :(得分:0)
我在将参数传递给url时实际上是错误的,应该以这种方式完成
<a class="btn btn-success" href="index.php?r=followusers/follow&id=<?= $follower1;?>&usr=<?= $followed1;?>" >Follow</a>
instead of above in the view1.php