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.

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!

You can do your customization in you model's function level. If you provide why do you extend the model, I can say whether it makes sense or not. If you want to create a user specific rule, you had better to do it on a controller.

class Shop_m extends CI_Model {

 function getProductPriceInfo($cat,$id) {
        $this->db->where('shop_price.catid', $cat); 
                $this->db->where('shop_price.relid', $id); 
                $this->db->select('optional.title,optional.desc,shop_price.*');
                $this->db->join('optional', 'optional.id = shop_price.relid');
        $q = $this->db->get('shop_price');
        if($q->num_rows() > 0) {
            foreach ($q->result() as $row) {
                $data[] = $row;
            }
        return $data;
        }
    } 

you can instantiate the class it self, instead of loading it.

$permission = new Permission($param);