duandi1919 2019-06-08 06:11
浏览 29

如何使用codeigniter将参数传递给自定义库?

I am creating a custom library in codeigniter, i want to pass parametere in constructor. Any solution appriciated!

function __construct( $iteration_count_log2, $portable_hashes )
    {
        $this->itoa64 = 
'./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

    if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
        $iteration_count_log2 = 8;
    $this->iteration_count_log2 = $iteration_count_log2;

    $this->portable_hashes = $portable_hashes;

    $this->random_state = microtime() . uniqid(rand(), TRUE); // removed getmypid() for compatibility reasons
}

Here is the code for loading library

public function __construct() {
    parent::__construct();
    $this->load->library('PasswordHash');
}
  • 写回答

1条回答 默认 最新

  • dpepbjp126917 2019-06-08 06:27
    关注

    From the docs: https://www.codeigniter.com/user_guide/general/creating_libraries.html#passing-parameters-when-initializing-your-class

    When initializing your library:

    $params = array('type' => 'large', 'color' => 'red');
    
    $this->load->library('someclass', $params);
    

    Your library:

    class Someclass {
    
            public function __construct($params)
            {
                    echo $params['type']; // large
            }
    }
    

    Notice: only one parameter can come through with CI, so if you want to send multiple parameters it must be sent via one parameter as an array as shown above.

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制