Reputation: 656
I have updated my config variable in my model using:
$this->config->set_item('userid', $user_id);
if i echo it in the model i can see that it gets set.
But if i echo it in the controller or another model using:
echo $this->config->item('userid');
it shows the original value.
I need to store this config variable throughout the session but i do not want to use session variables.
Upvotes: 2
Views: 8732
Reputation: 4527
that configurtation is only applicable on that model which you set it. If you want a global setting without using session.
you could create a core model on application/core
and name it
MY_Model
so basically what MY_Model
do is that it sets your config on all models that extends it.
class MY_Model Extends CI_Model
{
protected $user_id;
public function __construct()
{
parent::__construct();
$this->config->set_item('userid', $this->user_id);
}
}
then on your model that you want the settings to be applied, just extends your model. like
Model extends MY_Model
{
public function test($id)
{
$this->user_id = $id;
}
}
OR you could create a Core COntroller same as the above but substituting controller to model read more at Codeigniter Extending Core Classes
Upvotes: 5
Reputation: 2704
Try to initialize the config $this->ci = & get_instance();
and then set the value like
$this->ci->config->set_item('userid', $user_id);
I have not tested this... but I assume it will work.
Upvotes: 0