好的,我正在尝试将参数传递给我创建的库的构造函数,以扩展CI_Form_validation类。 无论如何,这是我从模型中传递的内容:
$this->load->library('MY_Form_validation', array('config' => '', 'post' => $this->input->post()));
然后是MY_Form_validation库:
private $post;
public function __construct($params) {
parent::__construct($params['config']);
$this->post = $params['post'];
}
但它说我没有传递任何内容。以下是错误消息:
Message: Missing argument 1 for MY_Form_validation::__construct(), called in H:\WD SmartWare.swstor\HALEY-HP\Source\DStable\stable\core\Loader.php on line 1099 and defined
Message: Undefined variable: params
EDIT 根据要求,全班:
class MY_Form_validation extends CI_Form_validation {
private $post;
public function __construct($params) {
parent::__construct($params['config']);
$this->post = $params['post'];
}
}
答案 0 :(得分:1)
您需要传递一个空数组而不是空字符串作为构造函数的第一个参数,该参数将发送给父级:
$this->load->library('MY_Form_validation', array('config' => array(), 'post' => $this->input->post()));
CI表单验证库实际上初始化了config参数,这是system/libraries/Form_validation.php
的构造函数:
public function __construct($rules = array())