Welcome Guest, Not a member yet? Register   Sign In
Setting a globally used function to run automatically
#1

[eluser]hightower[/eluser]
Hi folks,

I'm working on a project and have stumbled across something I need to sort before I proceed further. I'll try my best to explain this, so stay with me Smile

I have various controllers - here is the example code from one of them:

Code:
class Welcome extends Controller()
{

    function index()
    {
        $data = custom_helper_to_process_data_used_in_header_view();

        $this->load->view('header',$data);
        $this->load->view('content');
        $this->load->view('footer');
    }

}

As you can see, a custom function is called which returns some data. This data is then sent to the header view and then the content and footer are loaded after. My custom helper function is to be used on every page that is loaded, and the data retrieved is then always passed to the header view - this is because some of the menu's from the header view require information from the database, and this information needs to be displayed on each page.

My question is how would I go about processing this automatically for each page (i.e. calling the function and assigning the returned data to a variable before passing it to the header view) as it's a bit tedious to write this code in every page.

I know I could have a controller like this:

Code:
class Welcome extends Controller()
{
    function Welcome()
    {
        $data = custom_helper_to_process_data_used_in_header_view();
        $this->load->view('header',$data);
    }

    function index()
    {
        $this->load->view('content');
        $this->load->view('footer');
    }

}

But I would need to repeat this for each controller I make, which could be quite a few.

Any ideas?


Messages In This Thread
Setting a globally used function to run automatically - by El Forum - 06-29-2009, 07:08 AM
Setting a globally used function to run automatically - by El Forum - 06-29-2009, 08:07 AM
Setting a globally used function to run automatically - by El Forum - 06-29-2009, 08:09 AM
Setting a globally used function to run automatically - by El Forum - 06-29-2009, 08:14 AM
Setting a globally used function to run automatically - by El Forum - 06-29-2009, 08:39 AM
Setting a globally used function to run automatically - by El Forum - 06-29-2009, 08:46 AM
Setting a globally used function to run automatically - by El Forum - 06-29-2009, 09:16 AM
Setting a globally used function to run automatically - by El Forum - 06-29-2009, 09:31 AM
Setting a globally used function to run automatically - by El Forum - 06-29-2009, 11:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB