PHP名称空间问题

时间:2016-06-02 09:45:30

标签: php namespaces

这是我的示例项目的目录结构:

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(); } } 为每个类使用静态方法会使代码变得丑陋和不清楚。我需要做些什么改变才能在不同命名空间的代码中使用简短的类名?这可能吗?

0 个答案:

没有答案