Welcome Guest, Not a member yet? Register   Sign In
Passing vars from MY_Controller to child controllers and views
#1

[eluser]suntrop[/eluser]
Hi there.

I want to have some variables from a config table in my DB. Since I need them everywhere I'm loading them in MY_Controller. But somewhere between the controller and the view they get lost. print_r writes blank array to my screen.

MY_Controller.php [EDIT: code is in constructor]
Code:
$this->load->model('global_model');
$config_db = $this->global_model->get_config_db();

global_model.php
Code:
function get_config_db()
    {
        $query = $this->db->get('config');
        return $query->result_array();
    }

Welcome Controller (welcome controller extends public controller which extends MY_controller)
Code:
$data['app_config'] = $this->config_db;  // this should come from MY_controller
$data['content'] = 'welcome';
$this->load->view('includes/template_public', $data);

... and in my view:
<pre>&lt;?php print_r($app_config); ?&gt;</pre>

But all I see is
Array
(
)

How do I access the vars from the MY_Controller in a subset controller?

Hope someone can please help.


Messages In This Thread
Passing vars from MY_Controller to child controllers and views - by El Forum - 02-10-2011, 08:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB