1

以下のスニペットを使用して、いくつかのフォルダーからクラスを自動ロードしています。

// Check if the autoload configuration file exists
if(is_file("configuration/autoload")) {
    // Extract the listed folders from the configuration file
    $folders = explode("\n", file_get_contents("configuration/autoload"));
    // Prepend the base path to the extracted folder paths
    array_unshift($folders, get_include_path());
    // Configure the folders in which to attempt class autoloading
    set_include_path(implode(PATH_SEPARATOR, $folders));
    // Configure the file extensions that should be autoloaded
    spl_autoload_extensions(".php");
    // Administer the attempt to autoload classes
    spl_autoload_register();
}

いくつかのフォルダは、次のようにファイルに一覧表示されます。

core/utility
core/factory
core/modules
core/classes
core/classes/form
core/classes/form/fields
frontend

ローカルではチャームのように機能しますが、オンラインサーバーで機能させることができません(関連するすべてのファイルとフォルダーをCHMODしました)。インクルードパスの設定中に問題が発生していると思いますが、頭を包み込むことができないようです。

何か案は?

ありがとう

4

2 に答える 2

1

独自の autoload 関数、つまり my_autoloader を作成することをお勧めします。このようにして、フォルダ処理を完全に制御できます。

function my_autoloader($className)
{
    $parts = explode('\\', $className); //split out namespaces
    $classname = strtolower(end($parts)); //get classname case insensitive (just my choice)

        //TODO: Your Folder handling which returns classfile

    require_once($loadFile); 
}
spl_autoload_register(__NAMESPACE__ . '\my_autoloader');

異なる名前空間を処理することを忘れないでください

于 2013-01-08T23:05:40.030 に答える
0

これは、Magento eCommerce の方法です。

function __autoload($class)
{
    if (defined('COMPILER_INCLUDE_PATH')) {
        $classFile = $class.'.php';
    } else {
        $classFile = uc_words($class, DIRECTORY_SEPARATOR).'.php';
    }

    include($classFile);
}

次に、次の構造になります。

class Company_Category_Class{}

そして、次の制限 (インクルード パスに "lib" があると仮定):

./lib/Company/Category/Class.php

ご不明な点がございましたら、お知らせください。

于 2013-01-08T23:14:54.670 に答える