Ok I'm trying to pass parameteres to the constructor of my library I created to extend the CI_Form_validation class. Anyway, here is what I'm passing from my model:
好吧,我正在尝试将参数传递给我创建的库的构造函数,以扩展CI_Form_validation类。无论如何,这是我从模型中传递的内容:
$this->load->library('MY_Form_validation', array('config' => '', 'post' => $this->input->post()));
Then here is the MY_Form_validation library:
然后是MY_Form_validation库:
private $post;
public function __construct($params) {
parent::__construct($params['config']);
$this->post = $params['post'];
}
But it's saying I'm not passing anything in. Here are the error messages:
但是它说我没有传递任何内容。以下是错误消息:
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 On request, the whole class:
编辑根据要求,全班:
class MY_Form_validation extends CI_Form_validation {
private $post;
public function __construct($params) {
parent::__construct($params['config']);
$this->post = $params['post'];
}
}
1 个解决方案
#1
1
You need to just pass an empty array instead of an empty string as the first parameter to your constructor, which is sent to the parent:
您需要传递一个空数组而不是空字符串作为构造函数的第一个参数,该参数将发送给父级:
$this->load->library('MY_Form_validation', array('config' => array(), 'post' => $this->input->post()));
The CI Form Validation library actually initializes the config argument as such, this is the constructor from system/libraries/Form_validation.php
:
CI表单验证库实际上初始化了config参数,这是来自system / libraries / Form_validation.php的构造函数:
public function __construct($rules = array())
#1
1
You need to just pass an empty array instead of an empty string as the first parameter to your constructor, which is sent to the parent:
您需要传递一个空数组而不是空字符串作为构造函数的第一个参数,该参数将发送给父级:
$this->load->library('MY_Form_validation', array('config' => array(), 'post' => $this->input->post()));
The CI Form Validation library actually initializes the config argument as such, this is the constructor from system/libraries/Form_validation.php
:
CI表单验证库实际上初始化了config参数,这是来自system / libraries / Form_validation.php的构造函数:
public function __construct($rules = array())