dsp1836 2012-04-14 09:21
浏览 101
已采纳

codeigniter加载一个具有带参数的构造函数的模型

My model class:

<?php class Permissions extends CI_Model {

    private $userID   = '';
    private $permissions = '';

    function __construct($userID)
    {
        // Call the Model constructor
        parent::__construct();

        $this->userID = $userID;
        ....
    }
    function __construct()
    {.....}
?>

and I want to load this model with a parameter, apparently I could not do it. Without a parameter I can load parameterless constructor by this way:

$this->load->model('Permissions');

My first question: is loading a model with a parameter nonsense? Second one: if it is doable, how can I do that? Thanks in advance.

  • 写回答

3条回答 默认 最新

  • dongtui9168 2012-04-14 11:03
    关注

    You could take a look at this forum thread: http://codeigniter.com/forums/viewthread/115681/

    But I can't see why would you want to give a userid as a parameter in a way for permission checking? Guessing you use sessions to save userdata, write the userid in the session and call this in the Model with $this->session->userdata('user_id').

    Happy coding!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器