Answer the question
In order to leave comments, you need to log in
Generated crud does not open. Yii2?
No matter how much I generated, everything was fine. And then I made a new table, I try to open it, and 404 crashes.
I have site.ru/admin/
With the new generated CRUD - the application should open site.ru/admin/offerprice
And it does not open and gives a 404 error. The code is in the comments. Tell me what's wrong and how to fix it?
Answer the question
In order to leave comments, you need to log in
Can you be a little more specific? I think I just think that there is no folder that should be in the view, well, maybe the URL is not configured
Model:
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "offer_prise".
*
* @property integer $id
* @property string $value
* @property integer $id_tovar
*/
class OfferPrise extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'offer_prise';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_tovar'], 'required'],
[['id_tovar'], 'integer'],
[['value'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'value' => 'Value',
'id_tovar' => 'Id Tovar',
];
}
}
<?php
namespace backend\controllers;
use Yii;
use common\models\OfferPrise;
use common\models\OfferPriseSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* OfferPriseController implements the CRUD actions for OfferPrise model.
*/
class OfferPriseController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all OfferPrise models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new OfferPriseSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single OfferPrise model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new OfferPrise model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new OfferPrise();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing OfferPrise model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing OfferPrise model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the OfferPrise model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return OfferPrise the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = OfferPrise::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
/* @var $this yii\web\View */
/* @var $searchModel common\models\OfferPriseSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Offer Prises';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="offer-prise-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Create Offer Prise', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php Pjax::begin(); ?> <?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'value',
'id_tovar',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php Pjax::end(); ?></div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question