Salve ho una pagimna di creazione di un record , quando creo il record (actionCreate ) o ne modifico uno ( actionUpdate ) invece di andare nella view mi da errore 404 , perchè ?
di seguito il controller :
<?php
namespace app\controllers;
use Yii;
use app\models\Film;
use yii\data\ActiveDataProvider;
use yii\web\AccessControl;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* FilmController implements the CRUD actions for Film model.
*/
class FilmController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => ['create', 'update','filminseriti','filmgiainserito','view'],
'rules' => [
// allow all POST requests
[
'allow' => true,
'verbs' => ['POST']
],
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/**
* Lists all Film models.
* @return mixed
*/
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
'query' => Film::find(),
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Film model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Film model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Film();
//assegno una variabile al valore array
$mymovies=$_POST['Film']['mymovies'];
//conto se ci sono altri film con lo stesso mymovies...
$count = Film::find()->where(['mymovies' => $mymovies])->count();
if($count==0){
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->IdFilm]);
}
else {
return $this->render('create', [
'model' => $model,
]);
}
}
else{
$messaggio='Il film e` gia` presente , se sei tu l\'inserzionista e vuoi modificarlo premi su propri film inseriti
se vuoi inserire lo stesso film ma con una qualità maggiore contatta l\'amministratore cliccando su contatti in alto
';
return $this->render('filmgiainserito', [
'messaggio' => $messaggio,
]);
}
}
/**
* Updates an existing Film 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->IdFilm]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing Film 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(['site/index']);
}
/**
* Finds the Film model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Film the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Film::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/************************Create da me *****************************************/
public function actionPresentazione(){
$id=$_GET['id'];
$film = Film::find()
->where(['IdFilm' => $id])
->one();
return $this->render('presentazione',[
'film'=>$film
]);
}
public function actionFilminseriti(){
$id=Yii::$app->user->identity->id;
$filmInseriti = Film::find()->where(['utente' => $id])->orderBy('data_ins')->all();
return $this->render('filminseriti',[
'filmInseriti'=>$filmInseriti
]);
}
}