Welcome Guest, Not a member yet? Register   Sign In
putting an argument in my main template
#1

[eluser]Wondering Coder[/eluser]
hi codeigniter's families

first of all this is my first time to used codeigniter MVC and i'm in love with it. Also i'm not that good in PHP though. So please bear with me. Here goes.. I have my main template to load which has the basic header, content and footer(see below). My problem is I don't know how to put my arguments.

template.php
Code:
<?
$this->load->view('includes/header');

if($classification == 'company')//undefine variable $classification
{
    $this->load->view('includes/com_leftnav');
}
else
{    
    $this->load->view('includes/stud_leftnav');
}

if(isset($content)) echo $content;

$this->load->view('includes/footer');
?>

it gives me an undefined variable. I know what this means but could anyone help me to fix this? BTW, i'm doing this kind of argument coz i have two different left navigation for student and company.
Any response will be very helpful to me. I'll keep checking on my topic.

For futher info here's my controller

Code:
function validate_credentials()
    {        
        $data['username'] = $this->input->post('username');
        $data['password'] = md5($this->input->post('password'));
        $data['classification'] = $this->input->post('classification');
        
        $query = $this->membership_model->validate($data);
        
    
        if($query) // if the user's credentials validated...
        {
            $data = array(
                'username' => $this->input->post('username'),
                'classification' => $this->input->post('classification'),//used in views
                'is_logged_in' => true
            );
            $this->session->set_userdata($data);
            
                if($data['classification'] == 'company')
                    {
                        $data = $this->input->post('classification');
                        redirect('com_site');
                        
                    }
                else
                    {
                        redirect('stud_site');
                    }
        }
        else // incorrect username or password
        {
            $this->index();
        }
    }
#2

[eluser]Cristian Gilè[/eluser]
If I haven't misunderstood what you are attempting to do, follow this steps:

in the index function of the com_site controller put this lines:

Code:
$data['classification'] = this->session->userdata('classification');

$this->load->view('template',$data);

in the index function of the stud_site controller put this lines:

Code:
$data['classification'] = this->session->userdata('classification');

$this->load->view('template',$data);


Cristian Gilè
#3

[eluser]Wondering Coder[/eluser]
@Christian

thanks for the tip. its working now. ^_^. you're my angel

cheers
-Wondering Coder




Theme © iAndrew 2016 - Forum software by © MyBB