doumei1955
2018-09-15 05:01
浏览 138
已采纳

致命错误:未捕获错误:在动态变量命名空间中找不到类

I have this main controller:

namespace App\Core;
/**
* Controller class
*/

class Controller
{
    /** @var View View The view object */
    public $View;
    public $templates;
    /**
     * Construct the (base) controller. This happens when a real controller is constructed, like in
     */
    public function __construct()
    {

    }

    public function loadModel($name) {

        $path = '\\App\\Front\\Model\\'.$name; // Not Work

        //$this->model = new \App\Front\Model\IndexModel(); Work

        $this->model = new $path;

        return $this->model;

    }
}

In IndexController I have:

namespace App\Front\Controller;

use App\Front\Model\IndexModel;

class IndexController extends \App\Core\Controller {

    public function index(){
        $this->loadModel('IndexModel()')->test();
    }
}

Now in action I see error:

Fatal error: Uncaught Error: Class '\App\Front\Model\IndexModel()' not found in /Applications/MAMP/htdocs/mvc/application/Core/Controller.php:64

how do fix error?

图片转代码服务由CSDN问答提供 功能建议

我有这个主控制器:

  namespace App \ Core  ; 
 / ** 
 *控制器类
 * / 
 
class Controller 
 {
 / ** @var查看视图视图对象* / 
 public $ View; 
 public $ templates; \  n / ** 
 *构造(基本)控制器。 在构造真实控制器时会发生这种情况,例如
 * / 
公共函数__construct()
 {
 
} 
 
公共函数loadModel($ name){
 
 $ path ='  \\ \\应用\\阵线型号\\” $名称;  // Not Work 
 
 // $ this-> model = new \ App \ Front \ Model \ IndexModel(); 工作
 
 $ this-> model = new $ path; 
 
返回$ this-> model; 
 
} 
} 
   
 
  

在IndexController中我有:

 命名空间App \ Front \ Controller; 
 
use App \ Front \ Model \ IndexModel; 
 
class IndexController extends \ App \  Core \ Controller {
 
公共函数索引(){
 $ this-> loadModel('IndexModel()') - > test(); 
} 
} 
   
 
 

现在我看到错误:

致命错误:未捕获错误:类'\ App \ Front \ Model \ IndexModel() '找不到/Applications/MAMP/htdocs/mvc/application/Core/Controller.php:64

nn

怎么做修复错误?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题