Welcome Guest, Not a member yet? Register   Sign In
passing data to the view
#1

[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.
?>
#2

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

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

[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).
#5

[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
#6

[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è
#7

[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.
#8

[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?
#9

[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è
#10

[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.




Theme © iAndrew 2016 - Forum software by © MyBB