简体   繁体   English

自动加载错误文件Codeigniter

[英]Autoload Error Files Codeigniter

I have an error_codes.php file located in application/libraries I have it autoloaded when CodeIgniter loads but the variables are not recognized in the controllers. 我在application/libraries有一个error_codes.php文件,我在CodeIgniter加载时自动加载了该文件,但在控制器中无法识别变量。 I get an undefined variable when loading the page. 加载页面时出现未定义的变量。 Am I loading the files wrong or do I have the variables wrong. 我加载文件错误还是变量错误。 I have tried it wihtout the static but no luck. 我已经尝试过了wihtout的static ,但没有运气。

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class error_codes {

    static $a200 = array('error' => 'NO', 'code' => '200', 'description' => 'none', 'message' => 'Request ok');
    static $a206 = array('error' => 'YES', 'code' => '206', 'description' => 'Partial Content', 'message' => 'Not enough location data!');
//    
    static $a400 = array('error' => 'YES', 'code' => '400', 'description' => 'Bad Request', 'message' => 'This is not a valid URL');
    static $a401 = array('error' => 'YES', 'code' => '401', 'description' => 'Unauthorized', 'message' => 'Did you provide valid API key?');
    static $a402 = array('error' => 'YES', 'code' => '402', 'description' => 'Username Exists', 'message' => 'Username already exists!');
    static $a403 = array('error' => 'YES', 'code' => '403', 'description' => 'No User Exists', 'message' => 'User does not exists!');
    static $a404 = array('error' => 'YES', 'code' => '404', 'description' => 'Invalid Parameters', 'message' => 'Not enough user parameters!');
    static $a406 = array('error' => 'YES', 'code' => '406', 'description' => 'Invalid Email', 'message' => 'Email is invalid!');

}

?>

You can not use static variables this way. 您不能以这种方式使用静态变量。 Convert them to public vars, this might do what you want. 将它们转换为公共变量,这可能会做您想要的。

Additionally run your code with a step-debugger and see if your file gets included. 另外,使用步进调试器运行代码,然后查看文件是否包含在内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM