Welcome Guest, Not a member yet? Register   Sign In
best way to get a query i always need into my view
#1

[eluser]skattabrain[/eluser]
in all my views, i load 1 header.php file to build the navigation. in that nav, i want to include a "Messages" link that will show up if there is a new unread message for the user in the database.

i want this on every page, all the time (aside form ajax calls) and i don't want to deal with it in every controller. i want to set it in 1 place and that's it.

basically i need this query run on every page load. any ideas on the best way to handle this?
#2

[eluser]stuffradio[/eluser]
I'm not sure, but you could probably make use of the autoload config.
#3

[eluser]sikkle[/eluser]
You have a look in the forum for modular extension Smile

see ya around
#4

[eluser]Brandon Dickson[/eluser]
You could extend the base controller and check the values in the constructor:
Code:
<?php
class MY_Controller extends Controller
{

        function MY_Controller(){

                parent::Controller();

                /* do mail check... */
               $this->messages = get_message();
        }

        ...

}
?>

Then in your header file, just check for the variables

Code:
<?php if(isset( $this->messages ) ): ?>

        your view code here

<?php endif ?>

Then just make sure that all your controllers inherit from MY_Controller.

-Brandon




Theme © iAndrew 2016 - Forum software by © MyBB