【发布时间】:2016-07-02 06:42:17
【问题描述】:
我对 yii 很陌生,我遇到了这个错误,我找不到它的原因。
站点控制器.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(模型)
<?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 文件也可以清理 url。
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
]
【问题讨论】:
-
yiiframework.com/doc-2.0/guide-start-hello.html 创建小型测试平台并继续构建代码。
-
请显示您用于调用用户表单的确切链接/网址
-
据我了解,这段代码没有错误。作为@Scais Aksed,请输入您的网址。您如何访问它。
-
对不起,我已按要求更新了我的帖子。
-
能否请您在提交前和提交后在浏览器中提供链接?
标签: php model-view-controller yii yii2