1 回答

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊
我認(rèn)為你應(yīng)該使用自動(dòng)加載類來(lái)加載你使用的任何類,如果你不使用命名空間創(chuàng)建文件夾,將此代碼放在你創(chuàng)建的文件夾上的文件中,然后將它包含或要求在索引和 APP_PATH const 中作為路徑項(xiàng)目我希望這對(duì)你有幫助
<?php
namespace Services\lib;
class Autoload
{
public static function autoload($className){
//remove the main namespace
$className=str_replace("Services","",$className);
$className=str_replace("\\","/",$className);
$className=$className.".php";
$className=strtolower($className);
//echo $className;
if(file_exists(APP_PATH.$className)){
require_once (APP_PATH.$className);
}
}
}
spl_autoload_register(__NAMESPACE__.'\Autoload::autoload');
- 1 回答
- 0 關(guān)注
- 174 瀏覽
添加回答
舉報(bào)