Welcome Guest, Not a member yet? Register   Sign In
Setting a global variable in a controller?
#1

[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);
    }
    
}
?>


Messages In This Thread
Setting a global variable in a controller? - by El Forum - 08-07-2008, 11:42 AM
Setting a global variable in a controller? - by El Forum - 08-07-2008, 01:28 PM
Setting a global variable in a controller? - by El Forum - 08-07-2008, 01:29 PM
Setting a global variable in a controller? - by El Forum - 08-07-2008, 02:02 PM
Setting a global variable in a controller? - by El Forum - 08-07-2008, 02:06 PM
Setting a global variable in a controller? - by El Forum - 08-07-2008, 02:52 PM
Setting a global variable in a controller? - by El Forum - 08-08-2008, 12:15 AM
Setting a global variable in a controller? - by El Forum - 08-08-2008, 12:33 AM
Setting a global variable in a controller? - by El Forum - 08-08-2008, 01:03 AM
Setting a global variable in a controller? - by El Forum - 08-08-2008, 01:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB