[eluser]xtremer360[/eluser]
I'm trying to figure out if my class variables are looking correct and I'm using them properly. As with another question is I have some code that is used in multiple places so I'm trying to figure out what I can move to my Admin_Controller and make it into a function.
Code:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Dashboard extends Admin_Controller {
protected $current_user;
protected $data;
public function __construct() {
parent::__construct();
$this -> load -> model('user_model', 'user');
$user_id = $this -> session -> userdata('user_id');
if ($user_id == FALSE) {
redirect('login', 'refresh');
}
else {
if ((!is_numeric($user_id)) || (strlen($user_id) < 5)) {
$this -> session -> unset_userdata('user_id');
$this -> session -> sess_destroy();
redirect('login', 'refresh');
}
else {
$this -> current_user = $this -> user -> get($user_id);
if (!is_object($this -> current_user)) {
$this -> session -> unset_userdata('user_id');
$this -> session -> sess_destroy();
redirect('login', 'refresh');
}
else {
$this -> data['current_user'] = $this -> current_user;
}
}
}
}
public function index() {
if ($this -> current_user -> user_role_id >= 4) {
$dashboard = 'admin_dashboard';
}
else {
$dashboard = 'user_dashboard';
}
$this -> template -> set_theme('saturn') -> set_layout('default', 'admin') -> set_partial('header', 'admin/partials/header') -> set_partial('navigation', 'admin/partials/navigation') -> build('admin/' . $dashboard, $data);
}
}