无法在laravel 5.2中找到命名空间中的类

时间:2016-03-07 07:56:21

标签: php laravel laravel-5.2

Ui文件夹路径=>资源\视图\ DistributorRegitration.php

< ?php

namespace resources\views;

    class DistributorRegitrationForm
    {

        public  function distributorRegitrationFormHtml(){

            return  'hello'
    }

    }

Controller folder path =&gt;应用\ HTTP \控制器\ DistributorRegistration.php

< ?php 

namespace App\Http\Controllers;

use App\User;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use resources\views\DistributorRegitrationForm;


class DistributorRegistration  extends Controller

{ 

public function VestigePOS_DistributorRegistration()

{

$distribtutor_reg_form_obj = new DistributorRegitrationForm(); //class in DistributorRegistration.php            
$returned_dist_reg_html = $distribtutor_reg_form_obj->distributorRegitrationFormHtml(); // Function in DistributorRegistrationForm class.

return view($returned_dist_reg_html) ;      
}

}

?>

当我打电话给这个控制器 致命错误:Class&#39; resources \ views \ DistributorRegitrationForm&#39;未找到 enter image description here

3 个答案:

答案 0 :(得分:0)

resources\views\DistributorRegitration.php重命名为resources\views\DistributorRegitrationForm.php

答案 1 :(得分:0)

您需要在composer.json的autoload classmap部分注册文件或目录,以便自动加载该类。

{
    ...
    "autoload": {
        "classmap": [
            "database",
            "resources/views/"
        ]
    }
    ...
}

答案 2 :(得分:0)

重命名视图DistributorRegitration.blade.php并将其中的类移到app文件夹中的新文件中,例如名称为DistributorRegitrationFormClass.php

然后在控制器中改变这一行:

use resources\views\DistributorRegitrationForm;

use App\DistributorRegitrationForm;

和返回视图语句

return view('DistributorRegitration', ['returned_dist_reg_html' => $returned_dist_reg_html]);   

在视图中写{{returned_dist_reg_html}}并且神奇地&#39;你好&#39;会出现。