![](/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.