[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: <?php echo "$details->fname $details->sname" ?></p>
<p>Department: <?php echo $details->department ?></p>
<p>Job Title: <?php echo $details->jobRole ?></p>
<h3 class="overview-heading">Occupatinal Competence</h3>
<p><?php echo $details->competence ?></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>
<?php foreach ($cpd as $row) {?>
<tr>
<td><?php echo $row->course_title ?></td>
<td><?php echo ucfirst($row->course_type) ?></td>
<td><?php echo $row->course_expected_end_date ?></td>
</tr>
<?php } ?>
<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>
<?php foreach ($cpd as $row) {?>
<tr>
<td><?php echo $row->course_title ?></td>
<td><?php echo ucfirst($row->course_type) ?></td>
<td><?php echo $row->course_expected_end_date ?></td>
</tr>
<?php } ?>
<tbody>
</table>
<h3 class="overview-heading">2010 CPD Hours</h3>
<?php $this->load->view('includes/footer') ?>
Controller
Code:
<?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