[英]PHP laravel class not found. How can I use namespaces to fix this?
I'm using the Laravel framework and have a directory of the following structure: 我正在使用Laravel框架,并且具有以下结构的目录:
models
Statistic.php
presenters
StatisticPresenter.php
In my models/Statistic
class, I'm trying to access a present
method which calls a protected property which then references my presenter: 在我的
models/Statistic
类中,我试图访问一个present
方法,该方法调用一个受保护的属性,然后该属性引用我的演示者:
protected $presenter = 'presenters\StatisticPresenter';
public function present() {
return new $this->presenter($this);
}
Yet, this returns the error: Class 'presenters\\StatisticPresenter' not found
. 但是,这将返回错误:
Class 'presenters\\StatisticPresenter' not found
。 I realize this is a namespacing error of some sort, and I've tried watching a few videos on how it works, but I simply can't wrap my head around it. 我意识到这是某种命名空间错误,并且我尝试观看一些有关其工作原理的视频,但我实在无法解决这个问题。 I have already added my presenter folder to my
composer.json
file. 我已经将我的演示者文件夹添加到我的
composer.json
文件中。 For example, adding this to the top of my Statistic
model does not work: 例如,将其添加到我的
Statistic
模型顶部不起作用:
use presenters\StatisticPresenter;
How can I fix this? 我怎样才能解决这个问题?
Do the followings; 请执行以下操作;
{ "autoload": { "psr-4": { "presenters\\\\": "app/presenters/" } } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.