簡體   English   中英

PhalconPHP:如何自動加載

[英]PhalconPHP: how to autoload

我在使用PhalconPHP自動加載時找到了以下頁面: http ://docs.phalconphp.com/en/latest/reference/loader.html

我了解設置加載程序所需要做的事情。 但是,我的問題是,現在我有了一個$ loader變量...該如何處理? 我需要附加一些東西嗎? 我的猜測是將其添加到$ di中,但是$ di似乎沒有'loader'鍵。

// Creates the autoloader
$loader = new \Phalcon\Loader();

//Register some namespaces
$loader->registerNamespaces(
    array(
       "Example\Base"    => "vendor/example/base/",
       "Example\Adapter" => "vendor/example/adapter/",
       "Example"         => "vendor/example/",
    )
);

// register autoloader
$loader->register();

// ***  What goes here?

謝謝!

同樣不要忘記,如果您使用的是composer,那么對於任何特定於供應商的軟件包而言,始終堅持使用它的自動加載器總是很容易(而且常常更好),而且如果它遵循PSR-0 ,那么您也可以使用自己的代碼。

# composer.json
{

    "require": {
        "…": "…"
    },
    "autoload": {
        "psr-0": {
            "": "../src"
        }
    }
}

// Include composer's autoloader in your index.php.

include __DIR__ . '../vendor/autoload.php';
// Creates the autoloader
$loader = new \Phalcon\Loader();

//Register some namespaces
$loader->registerNamespaces(
    array(
       "Example\Base"    => "vendor/example/base/",
       "Example\Adapter" => "vendor/example/adapter/",
       "Example"         => "vendor/example/",
    )
);

// register autoloader
$loader->register();

$var = new Example\Base();

當您要使用指定的名稱空間和類時,它們會自動加載。

暫無
暫無

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

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