错误页面-404 Error
原始表格详细信息- crud form
我无法访问URL,我已经根据文档进行了原始操作,但是当我创建自己的结构时,找不到其显示页面。 如果您愿意,我也可以发布模型生成页面。 预先感谢
文件夹结构->
- models
-- UserModel
-controllers
--LoginFormController
-views
--loginform
---index.php
控制器代码
<?php
namespace app\controllers;
use Yii;
use app\models\UserModel;
use app\models\UserSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* LoginFormController implements the CRUD actions for UserModel model.
*/
class LoginFormController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all UserModel models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single UserModel model.
* @param string $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 UserModel model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new UserModel();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->username]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing UserModel model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param string $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->username]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing UserModel model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param string $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 UserModel model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $id
* @return UserModel the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = UserModel::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}
UserModel
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "user".
*
* @property string $username
* @property string $password
*/
class UserModel extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'user';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'password'], 'required'],
[['username', 'password'], 'string', 'max' => 52],
[['username'], 'unique'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'username' => 'Username',
'password' => 'Password',
];
}
}
答案 0 :(得分:0)
弄清楚,只需在URL中使用“-”,因为大写的LoginForm被解释为URL中的login-form