Welcome Guest, Not a member yet? Register   Sign In
extending native classes problem
#1

[eluser]devbro[/eluser]
I am working on a project and I ended up extending the native Controller class to achieve some neat and clever ideas that I had.

now I have a problem as I need to make a second set of extends for another part of the same application. in short:


class MY_Controller extends Controller

class MY_Controller_admin extends Controller


but for the second case I have to explicitly include it in order for it be found.

is there any suggestion on how I can fix this problem?
#2

[eluser]wiredesignz[/eluser]
Place both classes in the MY_Controller.php file.
#3

[eluser]devbro[/eluser]
that is the problem.

I am already using MY_Controller. I need to use another name. and there is no autoloader for Controllers.
#4

[eluser]helmutbjorg[/eluser]
Like wiredesignz said. Use different class names but put them both in the same file: MY_Controller.php
#5

[eluser]devbro[/eluser]
so there is no clean way of doing this then Sad.
#6

[eluser]Johan André[/eluser]
You should be able to use the autoloading-feature (PHP5).
#7

[eluser]helmutbjorg[/eluser]
Looks pretty bloody clean to me...

MY_Controller.php
Code:
class MY_Controller extends Controller {

}

class MY_Controller_admin extends Controller  {

}

End of MY_Controller.php
#8

[eluser]devbro[/eluser]
thanks for the help. I was hoping for a way that CI loads it automatically. Also I modified it to some extend:

In MY_Controller.php I am using include_once('MY_Controller_admin.php'). I have to follow some code restrictions and one of them is to use one class per file.

thanks for the help everyone.
#9

[eluser]wiredesignz[/eluser]
Remember also that include_once is not a function, it does not require parentheses.
Code:
include_once "MY_Controller_admin.php";
#10

[eluser]helmutbjorg[/eluser]
[quote author="devbro" date="1248064077"]I have to follow some code restrictions and one of them is to use one class per file.[/quote]

Ahh.. well that is annoying.

Also wired, not trying to be a stickler but include is a function. Just that some functions have shorthand versions (more common) that do not use brackets. Even echo is a function

Code:
echo('hello world');




Theme © iAndrew 2016 - Forum software by © MyBB