I have created new controller in the project with gii but I am getting Not Found (#404) error when I try to access it.please help me why i get this error? here is the controller:
<?php
namespace backend\controllers\phone;
use Yii;
use common\models\phone\UssdCode;
use backend\models\phone\UssdCodeSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* UssdCodeController implements the CRUD actions for UssdCode model.
*/
class UssdCodeController extends Controller
{
public function getViewPath()
{
// return \Yii::getAlias('@backend/views/phone/ussdcode');
}
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all UssdCode models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new UssdCodeSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single UssdCode model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new UssdCode model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new UssdCode();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->UssdCodeId]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing UssdCode 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)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->UssdCodeId]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing UssdCode 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)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the UssdCode model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return UssdCode the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = UssdCode::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}
and here is the model:
<?php
namespace common\models\phone;
use Yii;
/**
* This is the model class for table "tbl_ussd_code".
*
* @property int $UssdCodeId
* @property int $CategoryIdRef
* @property int $SubCategoryIdRef
* @property string $CodeDescription
* @property string $UssdCode
* @property int $Status
*/
class UssdCode extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'tbl_ussd_code';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['CategoryIdRef', 'SubCategoryIdRef', 'CodeDescription', 'UssdCode'], 'required'],
[['CategoryIdRef', 'SubCategoryIdRef', 'Status'], 'integer'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'UssdCodeId' => 'Ussd Code ID',
];
}
}
and here is the index:
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel \backend\models\phone\UssdCodeSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Ussd Codes';
$this->params['breadcrumbs'][] = $this->title;
?>
<?= Html::encode($this->title) ?>
<?= Html::a('Create Ussd Code', ['create'], ['class' => 'btn btn-success']) ?>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'UssdCodeId',
'CategoryIdRef',
'SubCategoryIdRef',
'CodeDescription',
'UssdCode',
//'Status',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Access url is: http://localhost/test/backend/ussdcode/index
why I get Not Found (#404)??
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)