gpt4 book ai didi

php - CodeIgniter 参数没有传递给库?

转载 作者:可可西里 更新时间:2023-10-31 23:42:02 25 4
gpt4 key购买 nike

好的,我正在尝试将参数传递给我创建的用于扩展 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

编辑根据要求,全类:

class MY_Form_validation extends CI_Form_validation {
private $post;

public function __construct($params) {
parent::__construct($params['config']);
$this->post = $params['post'];
}
}

最佳答案

您只需传递一个空数组而不是空字符串作为构造函数的第一个参数,该参数将发送给父级:

$this->load->library('MY_Form_validation', array('config' => array(), 'post' => $this->input->post()));

CI 表单验证库实际上是这样初始化配置参数的,这是来自 system/libraries/Form_validation.php 的构造函数:

public function __construct($rules = array())

关于php - CodeIgniter 参数没有传递给库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13783364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com