• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
running some function before view


I put notification bar on topbar. the data for notifications are set in MY_Controller.php
problem is:

For example there is notification where it says user has N unread messages. 
where N set in MY_Controller.
and then when user goes to unreaded message page, that notification should be decreased by 1, 
but as N set in MY_Controller and thus runs before Message Controller runs it will not be decreased by one.

What is the good way to solve this?


It is nearly impossible to comment without seeing the code you written.

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.

Thank u PauldD!
It solves my issue! thanks a lot

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.