Welcome Guest, Not a member yet? Register   Sign In
running some function before view

(This post was last modified: 05-31-2017, 10:48 AM by PaulD.)

You are using the pre-controller functions to do something that should not be done in the pre-controller IMHO. Often when implementing a complex header and sidebar, I will create a navigation_model that returns all the required data for the sidebar and header. Called just before the page loads the views, it will always be up to date.

For instance, every controller has this just before the page views are called:

PHP Code:
// get navigation data
$header_data['navigation_info'] = $this->navigation_model->get_navigation_info($user_id);

// load page views

Then, if I alter the sidebar, I just need to alter the one library file to provide data for all the pages using that layout.

It is much easier in fact if you have a layout_model or template_model to load the views, such as:

PHP Code:

Not a complicated model, but just means that if I decide to split the header and sidebar views, and have a right sidebar and left sidebar, or whatever, I only have to change the layout model, which itself calls the navigation model to get sidebar data for.

Now your controller has just one line in it to output the page once all your actions have been performed and your page data gathered. All the template or theme or layout data is gathered in the layout model. This also has the benefit that you can completely change the layout and design of your site, without having to address every controller call to load views. You only have to update the one layout_model.

Messages In This Thread
running some function before view - by neuron - 05-31-2017, 05:04 AM
RE: running some function before view - by PaulD - 05-31-2017, 10:46 AM
RE: running some function before view - by neuron - 06-01-2017, 04:03 AM

Theme © iAndrew 2016 - Forum software by © MyBB