CodeIgniter Forums
passing data to the view - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: passing data to the view (/showthread.php?tid=37365)

Pages: 1 2


passing data to the view - El Forum - 01-06-2011

[eluser]strattonbrazil[/eluser]
I can't seem to pass data to my view. This seems to be a popular question, but it's usually solved by something like the person not passing the array to the view, which I'm doing. I have my full controller and view shown below.

Code:
class Dashboard extends Controller {

        function Dashboard()
    {
        parent::Controller();
        }
    
    function index()
    {
            $data['controller_name'] = (string)get_class();

        $this->load->view('header', $data);
                $this->load->view('header_bg', $data);
                $this->load->view('navigation_bg', $data);
                $this->load->view('main', $data);
                $this->load->view('future', $data);
                $this->load->view('footer_bg', $data);
    }
}

I believe I might have seen somewhere someone sending view() another argument that looked like a path. Do I need to do that if I'm using mod_rewrite or something?

In my view...

<?
$controller_name; // causes a undefined variable error.
?>


passing data to the view - El Forum - 01-06-2011

[eluser]sooner[/eluser]
can u show ur actual view file?


passing data to the view - El Forum - 01-06-2011

[eluser]Atharva[/eluser]
In which view you are using
Code:
$controller_name
?


passing data to the view - El Forum - 01-07-2011

[eluser]strattonbrazil[/eluser]
[quote author="Atharva" date="1294399465"]In which view you are using
Code:
$controller_name
?[/quote]

navigation_bg.php. Would sending $data to all views somehow screw it up? Like the first one captures it and the rest don't get it?

And here's the view file attached (saved as an html since this forum won't attach php files for security reasons).


passing data to the view - El Forum - 01-07-2011

[eluser]InsiteFX[/eluser]
Try this:

Code:
class Dashboard extends Controller {

var $_ci;

function Dashboard()
{
parent::Controller();

$this->_ci =& get_instance();
}

function index()
{
$data['controller_name'] = $this->_ci->router->fetch_class();

$this->load->vars($data);

$this->load->view('header');
$this->load->view('header_bg');
$this->load->view('navigation_bg');
$this->load->view('main');
$this->load->view('future');
$this->load->view('footer_bg');
}
}

InsiteFX


passing data to the view - El Forum - 01-07-2011

[eluser]Cristian Gilè[/eluser]
Check if the $data array key match the var name in the view. Probably is only a typing error.

Cristian Gilè


passing data to the view - El Forum - 01-07-2011

[eluser]strattonbrazil[/eluser]
[quote author="InsiteFX" date="1294405666"]Try this:

Code:
$this->load->vars($data);

$this->load->view('header');
$this->load->view('header_bg');
$this->load->view('navigation_bg');
$this->load->view('main');
$this->load->view('future');
$this->load->view('footer_bg');
}
}

InsiteFX[/quote]

I'm not familiar with the vars functions, but if I replace $data with

$data['controller_name'] = 'Dashboard' it still doesn't work.


passing data to the view - El Forum - 01-07-2011

[eluser]strattonbrazil[/eluser]
[quote author="Cristian Gilè" date="1294422770"]Check if the $data array key match the var name in the view. Probably is only a typing error.

Cristian Gilè[/quote]

What do you mean, a typing error? Like a typo? I've posted my entire code and you can see it's not a typo, right?


passing data to the view - El Forum - 01-07-2011

[eluser]Cristian Gilè[/eluser]
What I mean is if there is in the view a var called $controller_name or you have accidentally missed out some character.

Cristan Gilè


passing data to the view - El Forum - 01-07-2011

[eluser]strattonbrazil[/eluser]
[quote author="Cristian Gilè" date="1294434078"]What I mean is if there is in the view a var called $controller_name or you have accidentally missed out some character.

Cristan Gilè[/quote]

Right, that's what I consider a typo. What I'm saying, though, is I've posted my entire controller and my entire view, and you can see I only use 'controller_name' once in each and they appear to match. You can verify this yourself.