Welcome Guest, Not a member yet? Register   Sign In
Setting session data in the controller
#1

[eluser]bcarter[/eluser]
Hi there, hope someone can help!

I am trying to set a session variable and I cannot for the life of me how to set it in the controller. I can set it no problem in the view but by this time it is too late!!!

Here's my code..

Model
Code:
class Update_model extends Model {
    
    function Update_model() {
        
        parent::Model();
    }
    
    function get_data()
    {
        $username = $this->session->userdata('username');
        $password = $this->session->userdata('password');
        
        $this->db->where('email', $username);
        //$this->db->where('password', $password);
        $query = $this->db->get('staff', 1);
        
        if($query->num_rows == 1)
        {
            $results = $query->row();
            return     $results;
        }        
    }
    
    function get_cpd_activity()
    {
        $staffID = $this->session->userdata('staffID');
        
        $this->db->where('course_staffID', $staffID);
        $query = $this->db->get('cpd_activity');
        
        $results = $query->result();
        return     $results;
    }
}

View
Code:
<?php
    
$staffID = $details->staffID;
$this->session->set_userdata('staffID', $staffID);

?>

<h1>CPD Overview</h1>

<h3 class="overview-heading">Personal Details</h3>

<p>Name: &lt;?php echo "$details->fname $details->sname" ?&gt;</p>
<p>Department: &lt;?php echo $details->department ?&gt;</p>
<p>Job Title: &lt;?php echo $details->jobRole ?&gt;</p>

<h3 class="overview-heading">Occupatinal Competence</h3>
<p>&lt;?php echo $details->competence ?&gt;</p>

<h3 class="overview-heading">CPD Activity</h3>

<h4>Current CPD Activity</h4>

<table class="wide-table margin-50btm">
    <tbody>
        <tr>
            <th width="50%">Course Title</th>
            <th width="30%">Course Type</th>
            <th width="20%">End Date</th>
        </tr>
        &lt;?php foreach ($cpd as $row) {?&gt;
        <tr>
            <td>&lt;?php echo $row->course_title ?&gt;</td>
            <td>&lt;?php echo ucfirst($row->course_type) ?&gt;</td>
            <td>&lt;?php echo $row->course_expected_end_date ?&gt;</td>
        </tr>
        &lt;?php } ?&gt;
    <tbody>
</table>

<h4>Recent Completed CPD Activity</h4>

<table class="wide-table margin-50btm">
    <tbody>
        <tr>
            <th width="50%">Course Title</th>
            <th width="30%">Course Type</th>
            <th width="20%">End Date</th>
        </tr>
        &lt;?php foreach ($cpd as $row) {?&gt;
        <tr>
            <td>&lt;?php echo $row->course_title ?&gt;</td>
            <td>&lt;?php echo ucfirst($row->course_type) ?&gt;</td>
            <td>&lt;?php echo $row->course_expected_end_date ?&gt;</td>
        </tr>
        &lt;?php } ?&gt;
    <tbody>
</table>

<h3 class="overview-heading">2010 CPD Hours</h3>

&lt;?php $this->load->view('includes/footer') ?&gt;

Controller
Code:
&lt;?php

class Cpd_zone extends Controller {

    function Cpd_zone()
    {
        parent::Controller();
        $this->is_logged_in();    
    }
    
    function is_logged_in()
    {
        $is_logged_in = $this->session->userdata('is_logged_in');
        if(!isset($is_logged_in) || $is_logged_in != true)
        {
            redirect('login');
        }        
    }
    
    function index()
    {
        $data['page_title'] = 'Continuous Professional Development';
        
        $this->load->model('Update_model');
        $data['details'] = $this->Update_model->get_data();
        $data['cpd'] = $this->Update_model->get_cpd_activity();
        
        $this->load->view('includes/head', $data);
        $this->load->view('home_view');
        $this->output->enable_profiler(TRUE);
    }

Can someone tell me how I can set it in the controller?

Cheers


Messages In This Thread
Setting session data in the controller - by El Forum - 08-18-2010, 04:45 AM
Setting session data in the controller - by El Forum - 08-18-2010, 07:21 AM
Setting session data in the controller - by El Forum - 08-18-2010, 07:46 AM
Setting session data in the controller - by El Forum - 08-18-2010, 10:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB