![](/img/trans.png)
[英]How to add another parameter to use in the php file while including a php file using shortcode in wordpress
[英]How the Class file is including in another file php using the namesapce and Use?
我有一個稱為Errors.php中的錯誤的類
namespace MyClass;
class Errors
{
private $_CODES = array(
301 => array(
"code"=> 301,
"message"=> "User With ID Not Found",
"type"=> "Error"
)
);
public static function getError($code)
{
return $this->_CODES[$code];
}
在Myclass.php中,我有
namespace MyClass;
use MyClass\Errors;
require'vendor/autoload.php';
在Myclass內部,我有功能,我正在檢查錯誤
echo Errors::getError(301);
它顯示類Myclass找不到錯誤
Fatal error: Class 'Myclass\Errors' not found in /var/www/Myclass/Myclass.php
我在這里錯過了什么?
您必須包括您的Errors.php
似乎您正在使用Composer的自動加載器。 您是否修改了“ composer.json”以使其為您加載?
也許像這樣:
“自動加載”:{“ classmap”:[“路徑/到/您/源/目錄”]}
此問題已解決。 Errors.php如下所示。
class Errors{
private static $_CODES = array(
301 => array(
"code"=> 301,
"message"=> "User With ID Not Found",
"type"=> "Error"
)
);
public static function getError($code) {
return self::$_CODES[$code]['message'];
}
}
並且我添加了require_once“ Errors.php”; 在MyClass.php文件中,現在我可以調用函數echo Errors::getError(301)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.