简体   繁体   English

Yii -Class'frontend \\ controllers \\ UserForm'找不到错误

[英]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.

相关问题 ajax上的yii 2.0提交错误类&#39;app \\ controllers \\ ActiveForm&#39;未找到 - yii 2.0 on ajax submit error Class 'app\controllers\ActiveForm' not found yii \\ base \\ ErrorException - 找不到类&#39;app \\ controllers \\ EntryForm&#39; - yii\base\ErrorException - Class 'app\controllers\EntryForm' not found YII PHP致命错误:找不到类“ CWebApplication” - YII PHP Fatal error: Class 'CWebApplication' not found 致命错误:找不到yii框架类“ CDbTestCase” - Fatal error: Class 'CDbTestCase' not found yii framework Yii2 gii crud 错误 Class 'app\models\Yii' not found - Yii2 gii crud error Class 'app\models\Yii' not found Yii2错误-找不到类&#39;yii \\ mongodb \\ ActiveRecord&#39; - Yii2 error - Class 'yii\mongodb\ActiveRecord' not found Yii2:找不到类“ Yii” - Yii2: Class 'Yii' not found 在第13行的C:\\ xampp \\ htdocs \\ basic \\ controllers \\ SiteController.php中找不到类“ yii \\ web \\ Controller” - Class ''yii\web\Controller'' not found in C:\xampp\htdocs\basic\controllers\SiteController.php on line 13 在前端/控制器中调用 yii2 控制台/控制器 - Calling yii2 console/controller inside frontend/controllers 致命错误:未捕获错误:Class“App\Http\Controllers\Controller”未在 - Fatal error: Uncaught Error: Class "App\Http\Controllers\Controller" not found in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM