Welcome Guest, Not a member yet? Register   Sign In
Parent (Application) Controller approach
#1

[eluser]introvert[/eluser]
Hello,

I have multi controller files which share the same code in each __construct as well as some other functions.

I don't like repeating myself when writing code, it would be much better to have this code at one place and call it from there.

Are there any CI approaches towards this?

How is it possible to call functions in other controllers?

Would be cool to have it like in Ruby on Rails where you have application controller.

Thanks in advance!
#2

[eluser]danmontgomery[/eluser]
This is covered in the user guide, under "Extending Core Class"
#3

[eluser]introvert[/eluser]
Are there any arhitecture examples - tutorials how other people use this functionality?
#4

[eluser]Jelmer[/eluser]
Search the forums for "MY_Controller". I'm using a variation on Jamie Rumbelow's base controller myself in 2 applications.

If you're up for something more advanced because you need multiple base controllers instead of just the one (CI supports only one variation on the Controller class) I'd recommend using a PHP5 autoloader and create a new directory where you keep base controllers which can be loaded through the autoloader.




Theme © iAndrew 2016 - Forum software by © MyBB