簡體   English   中英

zend無法識別注冊的名稱空間

[英]zend won't recognize registered namespace

我正在使用Zend Standard自動裝帶器。 它正在注冊一個名稱空間,但不會注冊另一個名稱空間。 這是我的代碼:

$zflib = $_SERVER['SERVER_ROOT'].'/classes/Zend_Framework_2/2.3.2/library';
require_once($zflib.'/Zend/Loader/StandardAutoloader.php');
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
// Library
$loader->registerNamespace('VProd',$_SERVER['SERVER_ROOT'].'/classes/VProd');
// Dealer Library
$loader->registerNamespace('Dealers', $_SERVER['SERVER_ROOT'].'/dealers/classes');
$loader->setFallbackAutoloader(true);
$loader->register();

然后,我在Dealers / classes目錄中進行了如下基本設置:

模型.php

<?php

namespace Dealers\Models;

class Model {
    /**
     * The table this model uses
     *
     * @var string
     */
    protected $table;
}

雞舍模型:

<?php

namespace Dealers\Models\Coop;

use Dealers\Models\Model;

class Coop extends Model {
    /**
     * The table this model uses
     *
     * @var string
     */
    protected $table = 'coop';

    public static function testing()
    {
        return 'testing';
    }
}

在我的應用程序中,我將在其他任何內容之前包含該配置文件。

coop.php

<?php
require_once($_SERVER['SERVER_ROOT'].'/security/config.php');

use Dealers\Model\Coop;
echo CoopBalance::testing();

我收到此錯誤消息:

致命錯誤:在第7行的\\ www \\ dealers \\ classes \\ coop \\ Coop.php中找不到類'Dealers \\ Models \\ Model'

這行在我的Coop模型中的位置:

class Coop extends Model

謝謝你的幫助!

ZF2標准自動裝帶器是符合PSR-0的自動裝帶器。 因此,您的班級應位於dealers/classes/Dealers/Models/Model.phpdealers/classes/Dealers/Models/Coop/Coop.php (區分大小寫)上,以正確正確地自動加載(名稱空間的每個“部分”應為夾)。

另外,如果可能的話,我建議您使用Composer安裝ZF2(或您使用的任何組件)。 然后,您根本不需要自己配置自動加載器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM