我对yii很新,我遇到了这个错误,我找不到它的原因。
SiteController.php
public function actionUserForm(){
$model = new UserForm();
if($model->load(Yii::$app->request->post()) && $model->validate()){
}else{
return $this->render('userform', [
'model' => $model,
]);
}
}
UserForm.php(Model)
<?php
namespace app\models;
use yii\base\Model;
class UserForm extends Model{
public $name;
public $email;
public function rules(){
return [
[['name', 'email'], 'required'],
//email form should look like an email
['email', 'email'],
];
}
}
userform.php(查看)
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php
$form = ActiveForm::begin();
?>
<?= $form->field($model, 'name'); ?>
<?= $form->field($model, 'email'); ?>
<?=
Html::submitButton('Submit', [
'class' => 'btn btn-success'
]);
?>
?>
之后,生成的页面将如下所示。你能帮助识别问题并善意指出代码中的错误吗?因为我对这个框架很新,我仍然开始对它有所了解。
我有一个.htaccess文件,可以清理网址。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
然后在web.php中,这是我清理它的第2步。这些是我在实际制作表格之前所做的。
'urlManager' => [
'enablePrettyUrl' => true,
//this will remove index.php in the url
'showScriptName' => false
//this is a two step process, after this go to the .htaccess in the web directory
]
答案 0 :(得分:0)
访问Yii2网址的正确方法不是cameCase,而是-
减去分隔符
... web/site/user-form