phpcs-类必须在至少一个级别的命名空间中-如何解决? [英] phpcs - class must be in a namespace of at least one level - how to fix?
问题描述
我正在使用laravel 4.2.
I am using laravel 4.2.
让我们说有这样的课程:
Lets say there is such class:
class BShopsController extends ShopsController
要解决此问题,我尝试使用名称空间,这样说:
To fix this, I try to use name space lets say this:
namespace app\controllers;
,然后找不到ShopsController
and then it does not find ShopsController
所以我添加
use \ShopsController;
然后我得到了错误:
BShopsController类不存在
Class BShopsController does not exist
我应该首先使用哪个名称空间,这样它才不会破坏任何内容?
What namespace should I use first of all so it would not break anything?
BShopsController和ShopsController在商店"文件夹中
BShopsController and ShopsController are in folder Shops
推荐答案
So with the help of Shhetri and this Using namespaces in Laravel 4
我是这样的:
namespace App\Controllers\Shops;
class BShopsController extends ShopsController{}
也可以在routes.php中将其更改为:
Also in routes.php then need to change to this:
Route::controller('shops', 'App\Controllers\Shops\ShopsController');
在调用action()方法的地方-也需要使用名称空间.
And where calling action() method - also need to use namespace.
还需要运行
composer dump-autoload -o
否则就是错误.
在ShopsContrller中也需要这样做:
Also in ShopsContrller needed to to this:
use \App\Controllers\BaseController;
因为Shops控制器位于BaseController之外的另一个命名空间中,所以找不到它.但是它是从BaseController扩展而来的,所以需要它.
Because Shops controller was in another namespace than BaseController and cannot find it. But is extending from BaseController, so need it.
这篇关于phpcs-类必须在至少一个级别的命名空间中-如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!