when creating from gii a CRUD from a table with multiple foreign key and when i try to access via the normal way without pretty url, it’s giving me a 404 error… for this application i’ve built 6 CRUD already (some has its own trouble), but i cannnot figure out what’s going on here…
i create the crud for the first tables…
Generating code using template "C:\Bitnami\wampstack-5.6.30-1\apache2\htdocs\mysoftware\vendor\yiisoft\yii2-gii\generators\crud/default"…
generated controllers\SeguridadUP2newController.php
generated views\seguridad-up2new\_form.php
generated views\seguridad-up2new\create.php
generated views\seguridad-up2new\index.php
generated views\seguridad-up2new\update.php
generated views\seguridad-up2new\view.php
done!
this is what web gii gave me or throws me…
at last i try to access
mysoftware/frontend/web/index.php?r=seguridad-up2new
and it’s giving me a 404 error
the table has a many to many relationship with 3 another one…
this is the model…
<?php
namespace frontend\models;
use Yii;
/**
-
This is the model class for table "seguridad_usuarios_programas_privilegios".
-
@property integer $idusuarios_programas_privilegios
-
@property integer $idusuario
-
@property integer $idprograma
-
@property integer $idprivilegio
-
@property SeguridadPrivilegios $idprivilegio0
-
@property SeguridadProgramas $idprograma0
-
@property SeguridadUsuarios $idusuario0
*/
class SeguridadUPPModel extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'seguridad_usuarios_programas_privilegios';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['idusuarios_programas_privilegios'], 'required'],
[['idusuarios_programas_privilegios', 'idusuario', 'idprograma', 'idprivilegio'], 'integer'],
[['idprivilegio'], 'exist', 'skipOnError' => true, 'targetClass' => SeguridadPrivilegiosModel::className(), 'targetAttribute' => ['idprivilegio' => 'idprivilegio']],
[['idprograma'], 'exist', 'skipOnError' => true, 'targetClass' => SeguridadProgramasModel::className(), 'targetAttribute' => ['idprograma' => 'idprograma']],
[['idusuario'], 'exist', 'skipOnError' => true, 'targetClass' => SeguridadUsuariosModel::className(), 'targetAttribute' => ['idusuario' => 'idusuario']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'idusuarios_programas_privilegios' => 'Idusuarios Programas Privilegios',
'idusuario' => 'Idusuario',
'idprograma' => 'Idprograma',
'idprivilegio' => 'Idprivilegio',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdprivilegio0()
{
return $this->hasOne(SeguridadPrivilegiosModel::className(), ['idprivilegio' => 'idprivilegio']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdprograma0()
{
return $this->hasOne(SeguridadProgramasModel::className(), ['idprograma' => 'idprograma']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdusuario0()
{
return $this->hasOne(SeguridadUsuariosModel::className(), ['idusuario' => 'idusuario']);
}
}
and this is the controller…
<?php
namespace frontend\controllers;
use Yii;
use frontend\models\SeguridadUPPModel;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
- SeguridadUPPController implements the CRUD actions for SeguridadUPPModel model.
*/
class SeguridadUPPController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all SeguridadUPPModel models.
* @return mixed
*/
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
'query' => SeguridadUPPModel::find(),
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single SeguridadUPPModel model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new SeguridadUPPModel model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new SeguridadUPPModel();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->idusuarios_programas_privilegios]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing SeguridadUPPModel 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->idusuarios_programas_privilegios]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing SeguridadUPPModel 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 SeguridadUPPModel model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return SeguridadUPPModel the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = SeguridadUPPModel::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
i’m using a bitnami 64 bit machine with mysql in windows…
also i got the source code from composer
and i executed the init command first… and also migrate command which gave me access to login logout and signup…
FYI i can access without no problem others CRUD… and they’re created well i mean i have to battle with the thing of frontend common and backend…
i’m sure it’s a problem with the code…