这是我的示例项目的目录结构:
htdocs/ <- xampp catalog
project/ <- projest
index.php <-- starter file, here I'm running engine cass
server/
Engine.php <- engine of routing, requesting and other
Controller.php <- main controller class
configs/
autoload.php <- incuded in index.php, it makes `require_once` for all controllers, models and tolls file
configuration.php
controllers/
aController.php <- extensions of main controller class.
bController.php
models/
aModel.php
bModel.php
tools/
aToll.php
bToll.php
我设置了以下内容:
Engine.php - namespace server;
Controller.php - namespace server;
aController.php - namespace controlls;
(或者我应该输入server\controllers
?)和use server;
因为类{{ 1}}扩展了类aController
。但代码Controller
放置
致命错误:Class&#39; server \ controllers \ Controller&#39;在第7行的C:\ xampp \ htdocs \ project \ server \ controllers \ aController.php中找不到
当我添加class aController extends Controller
命名空间并且代码为server
如何在class aController extends server\Controller
部分namespace
之内不使用classname
?
use
这段代码看起来并不凌乱,但接下来我使用namespace controllers;
use server;
class aController extends Controller
{
public function __construct()
{
parent::__construct();
}
}
为每个类使用静态方法会使代码变得丑陋和不清楚。我需要做些什么改变才能在不同命名空间的代码中使用简短的类名?这可能吗?