Welcome Guest, Not a member yet? Register   Sign In
Login box on multiple pages
#1

[eluser]Funky Fresh[/eluser]
Hey Hey,

I have been reading the article at http://codeigniter.com/wiki/Header_and_F...ge_-_jedd/ for quite some time and i cant wrap my head around how to pull this off.

So im going to post my code here in hopes that someone can help me.

Im trying to include a 'login box' on certain pages of my site ... if you could check it out that would be great.

I extended my core controller and created MY_Controller.php which is as follows

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends Controller
{

    function MY_Controller ()
    {
        parent::Controller();
        
        $this->load->helper('form');
        $this->load->library('form_validation');        
        
        // Login Box Info Start
        $tmp_data['check_this_out'] = 'insert data here';
        $tmp_data['config_options'] = 'some config rubbish here';
        
        $this->data['login_box_view'] = $this->load->view('inc/login_form', $tmp_data, TRUE);
        // Login Box Info End
    }

}

In the view that i want to display the login box i have the following code.

Code:
<?php echo $login_box_view; ?>

When i load up the page, i get the following error

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: login_box_view

I think im missing something hehe ... can someone please help me out.

Cheers,
#2

[eluser]SpooF[/eluser]
Can you post your other controller code? Like the code that is being executed where your loading the view thats giving you the error?
#3

[eluser]Funky Fresh[/eluser]
Im using the Tank Auth library, here is the controller

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Front extends MY_Controller {

    function Front()
    {
        parent::MY_Controller();
        
        $this->load->library('tank_auth');
        $this->load->helper('form');
        $this->load->library('form_validation');            
    }
    
    function index()
    {
        if (!$this->tank_auth->is_logged_in()) {
            $this->load->view('notloggedin_index');
        } else {
            $data['user_id']    = $this->tank_auth->get_user_id();
            $data['username']    = $this->tank_auth->get_username();
        
            $this->load->view('loggedin_index', $data);
        }
    }
}

It's the line that loads the notloggedin_index view.

Cheers,
#4

[eluser]dark_lord[/eluser]
Change this:
Code:
$this->data['login_box_view'] = $this->load->view('inc/login_form', $tmp_data, TRUE);


To something like:

Code:
$data['header']    = $this->load->view('inc/header', $tmp_data, TRUE);
$data['login_box'] = $this->load->view('inc/login_form', $tmp_data, TRUE);
$data['footer']    = $this->load->view('inc/footer', $tmp_data, TRUE);

Then pass it to another view:

Code:
$this->load->view('inc/login_page', $data);
#5

[eluser]dark_lord[/eluser]
Change this:
Code:
$this->data['login_box_view'] = $this->load->view('inc/login_form', $tmp_data, TRUE);


To something like:

Code:
$data['header'] = $this->load->view('inc/header', $tmp_data, TRUE);
$data['login_box']    = $this->load->view('inc/login_form', $tmp_data, TRUE);
$data['footer']       = $this->load->view('inc/footer', $tmp_data, TRUE);

#Then pass it to another view:

$this->load->view('inc/login_page', $data);

And on the view:

Code:
<?php echo $header; ?>
<?php echo $login_box; ?>
<?php echo $footer; ?>
#6

[eluser]SpooF[/eluser]
In your MY_Controller your saving your data into a class variable called data. In your controller your passing the local variable data and not the class variable.

Change this:
Code:
$data['user_id']    = $this->tank_auth->get_user_id();
            $data['username']    = $this->tank_auth->get_username();
        
            $this->load->view('loggedin_index', $data);

to:
Code:
$this->data['user_id']    = $this->tank_auth->get_user_id();
            $this->data['username']    = $this->tank_auth->get_username();
        
            $this->load->view('loggedin_index', $this->data);
#7

[eluser]Funky Fresh[/eluser]
Hey SpooF,

That worked perfect ... thanks heaps for that ... So to sum it up ( sorry about this ) ... using $data is only local and when using $this->data is more global?




Theme © iAndrew 2016 - Forum software by © MyBB