1. CI里面load的时候加载model是不可以在构造方法里面传参/比如我想自定义异常代码如下
- <?php
- class CrmException extends Exception {
- public function __construct() {
- parent::__construct();
- }
-
- public function initialise($message , $code = 0 )
- {
- $this->code = $code;
- $this->message = $message;
- }
-
- public function errorMessage()
- {
- //error message
- $errorMsg = 'Error on line '.$this->getLine().' in '.$this->getFile()
- .': '.$this->getMessage().' is not a valid E-Mail address';
- return $errorMsg;
- }
- public function getCustom() {
- return Array("code" => $this->code, "message" => $this->message);
- }
- }
- /* End of file Result.php */
- /* Location: ./system/models/common/CrmException.php */
可以将自定义的参数放在另外一个方法里面
- 引用的时候
- function test() {
- $this->load->model("common/CrmException");
- try {
- $object = new CrmException();
- $object->initialise("info" , 400 );
- throw $object;
- } catch (CrmException $e) { // 捕获异常
- print_r( $e->getCustom());
- }
- }
感觉有些怪怪的...
阅读(2987) | 评论(0) | 转发(0) |