Welcome Guest, Not a member yet? Register   Sign In
Menu system based on model names - how?
#1

[eluser]Jaketoolson[/eluser]
Currently, I am porting over a web system built entirely in PHP (no MVC, little OOP) over to CI. The primary use of this site is not CRUD, but mainly model-based algorithms. The main focus of the site is providing graphs, charts, and raw data to customers all of which is driven by forms the user interacts with. This data needs to be email-able, download-able in CSV format, and more which is why I'm moving it to a MVC method.

The site navigation menus are directly link to the name of models. Heres an example of my controller code (using this url example: http://site.com/index.php/reports/model_name) :

Code:
class Reports extends MY_Controller
{    
    function __construct()
    {        
        parent::__construct();
                  
        $this->options = array();
        $this->data = array();
        
        /** Models based on URI are loaded, so extract from URI **/
        parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);
        $this->options['uri'] = $this->security->xss_clean($this->uri->uri_to_assoc(4));
        $this->options['uri']['controller'] = $this->security->xss_clean($this->uri->segment(1));
        $this->options['uri']['action'] = $this->security->xss_clean($this->uri->segment(2));
        $this->options['uri']['id'] = @$this->security->xss_clean($this->uri->segment(3));

        /** Requested Controller Function **/
        $action = $this->options['uri']['action'];

        /**
         *  TODO: Need to just redirect to myaccount or login if the model doesn't exist.
         */
        if (file_exists(APPPATH.'models/'.$this->options['uri']['id'].EXT))
        {
            $this->model_name =  $this->options['uri']['id'];
            $model_name = $this->model_name;
        }
        else
        {
            redirect('/');
        }

        /** Load the model **/
        $this->load->model($model_name);

Is there a way I can pull the names of the models dynamically and generate the sites navigation? Is there a better way I can go about creating a dynamic menu based on model names? I'd just hate to maintain an array manually of the file names myself.


Messages In This Thread
Menu system based on model names - how? - by El Forum - 02-24-2011, 04:39 PM
Menu system based on model names - how? - by El Forum - 02-24-2011, 07:37 PM
Menu system based on model names - how? - by El Forum - 02-24-2011, 09:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB