Welcome Guest, Not a member yet? Register   Sign In
Using a function across multiple controllers
#1

[eluser]Mowgli[/eluser]
Hello,

Is there any way i could use a (externalized) function across multiple controllers ?
A possible answer would be using a helper but i cannot load lang files as it is not an object.

Here's a function from the default controller:

Code:
function account()
    {
        //START TEMPLATE
        $data['header'] = 'includes/header';
        $data['main_content'] = 'account';
        $data['footer'] = 'includes/footer';
        $data['menu'] = 'menu';
        //END TEMPLATE
        
        //START LANGUAGE FILES
        $this->lang->load('account','english');
        $this->lang->load('header','english');
        $this->lang->load('footer','english');
        $this->lang->load('menu','english');
        //END LANGUAGE FILES
        
        $this->load->view('includes/template', $data);
    }

I wouldn't normally do this but here's my problem. I decided do make a controller that handles all the form inputs across my website.

When i use form validation i actually have to reload the views (to display the errors) so i need to call that function. If i use redirect it won't work (obviously). One solution (that works) would be to copy the function(s) into my new controller but that won't help me as i don't want to have the same piece of code everywhere.

I even tried extending my default controller in order to inherit the above function but for some reason it won't work.

Any ideas ? Thanks in advance.


Messages In This Thread
Using a function across multiple controllers - by El Forum - 08-13-2011, 11:27 AM
Using a function across multiple controllers - by El Forum - 08-13-2011, 12:18 PM
Using a function across multiple controllers - by El Forum - 08-13-2011, 12:55 PM
Using a function across multiple controllers - by El Forum - 08-13-2011, 06:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB