Welcome Guest, Not a member yet? Register   Sign In
Re-implementing a new controller interface
#1

[eluser]kakawett[/eluser]
Hi there,

I'd like to know how to make a new controller, inherited from the codeigniter's core Controller one.
So that I could start my controllers like this:

class mycontroller extends InheritedController {...}

and use extra functions and variables I'd have defined in the InheritedController class which use the Controller one as a parent.
#2

[eluser]dudeami0[/eluser]
Seems like your looking for the MY_Controller functionality. This link will possibly help out. The basics are:

Create a class named MY_Controller. Place this in the libraries folder (or core for CI2) of the application folder. Class should look like:

Code:
class MY_Controller extends Controller {
   // CI_Controller replaces Controller in newer versions of CI2 I believe.
   ...
}

Then simply extend all your controllers with MY_Controller and you have your unique functions Smile
#3

[eluser]kakawett[/eluser]
yeah i've tried that but then I have the following error :

Fatal error: Class 'My_controller' not found in /home/www/m/http/application/controllers/welcome.php on line 3

In an old school PHP error style.
#4

[eluser]dudeami0[/eluser]
Whats the name of the PHP file (Containing the MY_Controller class)?
#5

[eluser]kakawett[/eluser]
Ok forget about it I talked too fast - created the class MY_Controller as explained on the link you gave me but the php file was nammed My_controller.

Thanks for the very fast answer Wink
#6

[eluser]Learn CodeIgniter[/eluser]
CI 1.7.2 Put MY_Controller in application/libraries
CI 2.0 Put MY_Controller in application/core
#7

[eluser]kakawett[/eluser]
hmmm where do you get the 2.0 version ?
#8

[eluser]Learn CodeIgniter[/eluser]
Codeigniter CI 2.0




Theme © iAndrew 2016 - Forum software by © MyBB