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

[eluser]duartix[/eluser]
You're very right. Loading the views shouldn't be done in the constructor. However, $data is still not recognized in the view. :-(
Any ideas?

The view application/views/logged.php wasn't changed.
The controller application/controllers/home.php is now:

Code:
<?php

class Home extends CI_Controller {

    public function __construct() {

        parent::__construct();

        // Initializes connection data
        $data['connection'] = array(
            'logged' => TRUE,
            'username' => 'duarte',
        );
    }

    public function index() {
        if ($data['connection']['logged']) {
            $this->load->view('templates/logged', $data);
        } else {
            $this->load->view('templates/login');
        }
    }

}


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



Theme © iAndrew 2016 - Forum software by © MyBB