[eluser]Matrices[/eluser]
Hello fellow CI-ers!
I need to set a global variable within a controller that all the functions can access. The variable is $omit. The code is below. As you can see the $omit variable needs to be plugged into each function right now. This variable will be the same no matter what, so is there a way to set it globally, but only inside this specific controller?
Code:
<?php
class Admin extends Controller {
function Admin()
{
parent::Controller();
$this->load->scaffolding('categories');
}
function index()
{
$this->load->view('admin');
}
function categories()
{
// Give the view page a title
$title = "Categories";
// Query the table
$query = $this->db->get('categories');
// Get the table fields
$fields = $this->db->list_fields('categories');
$omit = array(
'ID',
);
while (list ($key, $val) = each ($fields)) {
if (in_array ($key, $omit)) unset ($fields[$key]);
}
// Place all the data into an array
$data = array(
'query' => $query,
'fields' => $fields,
'title' => $title,
);
$this->load->view('admin', $data);
}
function articles()
{
// Give the view page a title
$title = "Articles";
// Query the table
$query = $this->db->get('articles');
// Get the table fields
$fields = $this->db->list_fields('articles');
$omit = array(
'ID',
);
while (list ($key, $val) = each ($fields)) {
if (in_array ($key, $omit)) unset ($fields[$key]);
}
// Place all the data into an array
$data = array(
'query' => $query,
'fields' => $fields,
'title' =>$title
);
$this->load->view('admin', $data);
}
}
?>