Welcome Guest, Not a member yet? Register   Sign In
Can't send data from controller to view - variable scope problem?
#5

[eluser]duartix[/eluser]
[quote author="noideawhattotypehere" date="1377868499"]

in view
Code:
<?php echo $username?>
[/quote]

It still doesn't recognize the variable.
Let me put it in the crudest of forms:

application/controllers/home.php :

Code:
<?php
class Home extends CI_Controller {
    public function index() {
        $username = 'ME!';
        $this->load->view('templates/logged', $username);
    }
}

application/views/templates/logged.php :

Code:
<?php echo $username ?>

This is what I get:

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: username
Filename: templates/logged.php
Line Number: 2


What am I doing wrong?


Messages In This Thread
Can't send data from controller to view - variable scope problem? - by El Forum - 08-30-2013, 06:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB