Answer the question
In order to leave comments, you need to log in
Why does it give the error "missing required parameters: id"?
Hello, I understand that the error arose due to a confusion of variables, although these are my assumptions .. The fact is that this error occurred in the update and in the view: update and view. I have already tried everything .. Please poke your nose where I made a mistake?
Controller:
<?php
namespace app\modules\admin\controllers;
use app\modules\admin\models\FaqLang;
use Yii;
use app\modules\admin\models\Faq;
use app\modules\admin\models\FaqSearch;
use yii\base\Model;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* FaqsController implements the CRUD actions for Faq model.
*/
class FaqsController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Faq models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new FaqSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Faq model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'faq' => $this->findModel($id),
]);
}
/**
* Creates a new Faq model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$faq = new FaqLang;
$faqLang = new Faq;
if ($faq->load(Yii::$app->request->post()) && $faqLang->load(Yii::$app->request->post()) && Model::validateMultiple([$faq, $faqLang]))
{
$faqLang->save(false);
$faq->faq_id = $faq->id;
$faq->save(false);
return $this->redirect(['view', 'id' => $faq->id]);
}
return $this->render('create', [
'faqLang' => $faqLang,
'faq' => $faq,
]);
}
/**
* Updates an existing Faq model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$faq = FaqLang::findOne($id);
$faqLang = Faq::findOne($faq->faq_id);
if ($faq->load(Yii::$app->request->post()) && $faqLang->load(Yii::$app->request->post()) && Model::validateMultiple([$faq, $faqLang]))
{
$faqLang->save(false);
$faq->save(false);
return $this->redirect(['view', 'id' => $faq->id]);
}
return $this->render('update', [
'faq' => $faq,
'faqLang' => $faqLang,
]);
}
/**
* Deletes an existing Faq model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$id_ = FaqLang::findOne($id)->faq_id;
Faq::findOne($id)->delete();
Faq::findOne($id_)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Faq model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return FaqLang
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($faq = FaqLang::findOne($id)) !== null) {
return $faq;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
}
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel app\modules\admin\models\FaqSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Faqs');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="faq-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('app', 'Create Faq'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['attribute' => 'name', 'value' => 'faqLang.name'],
['attribute' => 'body', 'value' => 'faqLang.body:ntext'],
'put_date',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $faqLang app\modules\admin\models\Faq */
/* @var $faq app\modules\admin\models\FaqLang */
//$this->title = $faq->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Faqs'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="faq-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $faq->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $faq->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'faq' => $faq,
'attributes' => [
'id',
['attribute' => 'name', 'value' => 'faqLang.name'],
['attribute' => 'body', 'value' => 'faqLang.body:ntext'],
'put_date',
[
'attribute' => 'hide',
'format' => 'html',
'value' => function($model) {
if($model->hide == 'show')
return 'Нет';
else
return 'Да';
}
],
],
]) ?>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $faqLang app\modules\admin\models\Faq */
/* @var $faq app\modules\admin\models\FaqLang */
$this->title = Yii::t('app', 'Update Faq: ' . $faq->id, [
'nameAttribute' => '' . $faq->id,
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Faqs'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $faq->id, 'url' => ['view', 'id' => $faq->id]];
$this->params['breadcrumbs'][] = Yii::t('app', 'Update');
?>
<div class="faq-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'faq' => $faq,
'faqLang' => $faqLang,
]) ?>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $faqLang app\modules\admin\models\Faq */
/* @var $faq app\modules\admin\models\FaqLang */
$this->title = Yii::t('app', 'Create Faq');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Faqs'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="faq-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'faq' => $faq,
'faqLang' => $faqLang,
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\jui\DatePicker;
use mihaildev\ckeditor\CKEditor;
/* @var $this yii\web\View */
/* @var $faqLang app\modules\admin\models\Faq */
/* @var $faq app\modules\admin\models\FaqLang */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="faq-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($faq, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($faq, 'body')->widget(CKEditor::className(),[
'editorOptions' => [
'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать
'inline' => false, //по умолчанию false
],
]); ?>
<?= $form->field($faqLang, 'put_date')->widget(DatePicker::class, [
'language' => 'ru-RU',
'dateFormat' => 'yyyy-MM-dd',
]) ?>
<?= $form->field($faqLang, 'hide')->dropDownList([ 'show' => 'Отображать', 'hide' => 'Скрыто']) ?>
<div class="form-group" style="margin-top: 46px;">
<?= Html::submitButton($faqLang->isNewRecord ? 'Создать' : 'Редактировать', ['class' => $faqLang->isNewRecord ? 'btn btn-success' : 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question