Welcome Guest, Not a member yet? Register   Sign In
call a controller function from another controller
#1

[eluser]datguru[/eluser]
Hi there,

Just wondering if it is possible to call a controller function from another controller.. so for example say I have Controller 1 that has a function called function 1 and then I have controller 2. I want to be able to access function1 of controller 1 from controller 2. Is that possible? the reason I want to do this is because I have a generic function that I want a few controllers to use.

Thanks
#2

[eluser]GSV Sleeper Service[/eluser]
In theory you call them like this - Controller1::function() - I haven't tried this in codeigniter though.
A generic function should really be in a library, or maybe a helper.
#3

[eluser]cereal[/eluser]
For the readers, try this solution: http://ellislab.com/forums/viewreply/748866/
#4

[eluser]bretticus[/eluser]
This is a perfect example of why you should have thin controllers and fat models.

Models are NOT just for storing database libraries. It is perfectly acceptable to store website logic in models.

So, when you need some specific data in more than one controller, just load the model for it and pass the data to the view. Done.




Theme © iAndrew 2016 - Forum software by © MyBB