【问题标题】:Where do I place an error object in CodeIgniter?我在 CodeIgniter 中的哪里放置错误对象?
【发布时间】:2011-11-15 19:53:38
【问题描述】:

在我当前的 PHP 网站中,我正在传递描述错误的字符串。我想摆脱这个 hacky 系统并改用错误代码,所以我创建了这个错误对象:

class Error 
{
   const DATABASE = 0; // database failure
   const CACHE    = 1; // cache miss
   const NETWORK  = 2; // network is down
   // ... etc ...
}

将此文件放置在 CodeIgniter 中的标准文件夹是什么?在控制器中加载此类文件的标准方法是什么?

【问题讨论】:

    标签: php codeigniter coding-style


    【解决方案1】:

    我可能会把它放在/application/libraries/ 中(参见Creating Libraries 了解 CodeIgniter 约定)。

    然后您将像这样加载库:

    $this->load->library('yourErrorClass');
    

    ..并像这样使用它的功能之一:

    $this->yourErrorClass->someLoggingFunction();
    

    【讨论】:

      猜你喜欢
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-14
      • 2012-01-15
      • 1970-01-01
      • 2019-03-27
      相关资源
      最近更新 更多