如何在yii2的动作评论中定义id_pst?

时间:2015-04-27 04:59:40

标签: yii2

我已经创建了这样的动作评论:

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,每个帖子都有特定的注释?

0 个答案:

没有答案