Welcome Guest, Not a member yet? Register   Sign In
Extending an extended core class
#1

[eluser]JCianflone[/eluser]
Hello,

I'm having this strange issue with CI 2.0. I'm working on this app that will have an Admin and a Front End. They are both unique but do share some common variables and do some common things. What I wanted to do was this:

Code:
class MY_Controller extends Controller {} //extend the controller for generic shared vars and functions

class MY_Front_Controller extends MY_Controller {}

class MY Admin_Controller extends MY_Controller {}

I then want to use them in this manor:

Code:
class Welcome extends MY_Front_Controller {}

(NOTE: I omitted constructor functions for easier reading)

I know I was able to do this in 1.7.2 with no issues, but now I'm getting an error saying that welcome.php can't find MY_Front_Controller

I think the issue is where I'm placing the files, there is no code in the files yet, so there isn't anything I could have done wrong!

I put ALL 3 functions in the core folder, but that doesn't seem to work. I did try moving the Front and Admin Controllers to the libraries folder too, but that didn't work either.

Any ideas?
#2

[eluser]InsiteFX[/eluser]
Try placing them in application/core

InsiteFX
#3

[eluser]JCianflone[/eluser]
Yep, I started with them all there and that didn't work either. I can extend just the conroller and that will work. So *this* works:

Code:
class MY_Controller extends Controller {}

class Welcome extends MY_Controller {}

That code works no problem, but as soon as I try to extend MY_Controller the whole thing breaks
#4

[eluser]InsiteFX[/eluser]
MY_Controller is the only Controller that
should be libraries the rest should be in
controllers.

InsiteFX
#5

[eluser]JCianflone[/eluser]
Sure, I could do that, but then I would need to put an include in my php file and would like to avoid that.

I'm extending a core class or so it seems, should I just be able to keep these files all in core? I very well could be missing something here, but putting in it Controller seems wrong.

Also, putting these two controllers in my Controller directory would make them accessible to the user, wouldn't it? I mean, it wouldn't have a view, but it could be accessed couldn't it?
#6

[eluser]cahva[/eluser]
I think this article might interest you:
http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY

With this you can make use of PHP 5 __autoload() magic function and you dont have to use MY_Controller at all(you just create Front_controller, Admin_controller etc. and extend from them in your normal controllers).




Theme © iAndrew 2016 - Forum software by © MyBB