$review->computer_id = $id;
$comments = Review::find()->where(['computer_id' => $id]);
public function actionIndex($id)
{
$model = new ReviewForm();
if ($model->load(Yii::$app->request->post())) {
if ($model->validate()) {
$review = new Review();
$review->setAttributes($model->getAttributes());
$review->computer_id = $id;
$review->save(false);
Yii::$app->session->setFlash('success', 'Данные приняты');
return $this->refresh();
} else {
Yii::$app->session->setFlash('error', 'Ошибка');
}
}
$comments = Review::find()
->where(['computer_id' => $id]);
$pagination = new Pagination([
'defaultPageSize' => 5,
'totalCount' => $comments->count(),
]);
$comments = $comments->orderBy('id Desc')
->offset($pagination->offset)
->limit($pagination->limit)
->all();
$computers = addComputer::findOne($id);
return $this->render('index', compact('model', 'comments', 'pagination', 'computers'));
}
<?= Html::a('Редактировать', Url::to(['computer/update', 'id' => $comment->id])) ?>
<?= Html::a('Редактировать', Url::to(['computer/update', 'id' => $comment->id, 'cid'=>$computers['id'] ])) ?>
public function actionUpdate($id,$cid)
{
$model = new ReviewForm();
$comment = Review::findOne($id);
if ($model->load($this->request->post())) {
$comment->text = $model->text;
if ($comment->save(false)) {
return $this->redirect(["computer/", "id"=> $cid]);
}
Yii::$app->session->setFlash(
'success',
'Success'
);
}
$model->setAttributes($comment->getAttributes(['name', 'email', 'text']));
return $this->render('update', compact('model'));
}
if($_POST['age'] >= 21) {
$link='maxage.php?name='.$_POST['name'];
header('location:'.$link);
}