我已经创建了这样的动作评论:
public function actionComment($id){
$text = CommentModel::find($id)->where(true)->all();
if(isset($_POST['name'])){
$text = new CommentModel();
$text->name=$_POST['name'];
$text->comment=$_POST['comment'];
$text->i_post=$_POST['id_post'];
$text->save();
$this->redirect('comment',array('id'=>$text->id));
}
return $this->render('comment',array("text"=>$text));
}
和评论视图是:
<h2>List of all comments:</h2>
<?php
foreach($text as $text[0]){
echo "name"." ".":"." ".$text[0]->name."<br>" ;
echo "comment"." ".":"." ".$text[0]->comment."<br>";
?>
我的评论模型是:
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
'comment' => 'Comment',
'id-post' => 'Id Post',
];
}
如何在我的项目中定义id_pst,每个帖子都有特定的注释?