我试图在帖子#{any nos.}
下收到所有评论,但是当我点击下面的URI时,我怎么能得到post_id
。例如帖子#1
关于GET URI:/posts/1/comments/
:
public function actions() {
$actions = parent::actions();
unset($actions['index']);
return $actions;
}
public function actionIndex($post_id)
{
return Comments::find()->where(['post_id' => $post_id])->all();
}
答案 0 :(得分:0)
在yii2中使用_urlManager
return [
'class'=>'yii\web\UrlManager',
'enablePrettyUrl'=>true,
'showScriptName'=>false,
'rules'=>[
// url rules
'posts/<post_id:\d+>/comments' => 'posts/index',
]
];