[英]Yii -Class 'frontend\controllers\UserForm' not found error
Yii frame work I place UserFrom.php
in root/models folder code is bellow Yii框架工作我将UserFrom.php
放在root / models文件夹中的代码如下
<?
namespace app\models;
use yii\base\Model;
class UserForm extends Model
{
public $name;
public $email;
public function rules()
{
return[[['name','email'],'required'],
['email','email'],]
}
}
?>
and modifi the root/frontend/controllers/ Sitecontroller.php
file . 并修改root/frontend/controllers/ Sitecontroller.php
文件。 add the following code 添加以下代码
public function actionUser()
{
$model=new UserForm;
if($model->load(Yii::$app->request->post()) && $model->valideate())
{
}
else
{
return $this->render('userForm',['model'=>$model] );
}
}
then finaly add new file in root/views/site/userForm.php
its code bellow 然后最后在root/views/site/userForm.php
添加新文件,其代码如下
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php $form=ActiveForm::begin();?>
<?php $form->field($model,'name'); ?>
<?php $form->field($model,'email'); ?>
<?php Html::submitButton('Submit',['class'=>'btn btn-success']);
if i open the url i am getting error url= http://localhost/yiicomm/frontend/web/index.php?r=site/user 如果我打开url,我将收到错误url = http://localhost/yiicomm/frontend/web/index.php?r = site / user
PHP Fatal Error – yii\\base\\ErrorException Class 'frontend\\controllers\\UserForm' not found. PHP致命错误– yii \\ base \\ ErrorException未找到类'frontend \\ controllers \\ UserForm'。 i feel i placed correcly but get error . 我觉得我摆放得很正确,但出错了。 what is wrong in my code 我的代码有什么问题
Try using the full namespace: 尝试使用完整的名称空间:
$model=new \app\models\UserForm;
Or include the following line at top of your controller: 或在控制器顶部添加以下行:
use app\models\UserForm;
您忘记了使用Use Operator获取类UserForm的全限定名称,例如
use app\\models\\Userform;
you can add 你可以加
use app\models\UserForm;
in your Controller 在您的控制器中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.