Welcome Guest, Not a member yet? Register   Sign In
abstract controller, banging head against a wall
#1

[eluser]andychurchill[/eluser]
I'm using Jamie Rumbelow's base controller, but now I'm trying to create a sub controller which extends MY_Controller, called AdminController, which does some common authentication checks in the constructor among other things. All my admin type Controllers then extend from AdminController.

I'm now trying to duplicate this structure from an old projct I was working on into a new project, but now all I'm getting is:

Fatal error: Class 'AdminController' not found in /home/phpdev/Projects/myproject/trunk/application/controllers/account/dashboard.php on line 24 Call Stack: 0.0005 337652 1. {main}() /home/phpdev/Projects/myproject/trunk/public_html/index.php:0 0.0020 400456 2. require_once('/home/phpdev/Projects/myproject/trunk/system/core/CodeIgniter.php') /home/phpdev/Projects/myproject/trunk/public_html/index.php:202 0.0165 1282308 3. include('/home/phpdev/Projects/myproject/trunk/application/controllers/account/dashboard.php') /home/phpdev/Projects/myproject/trunk/system/core/CodeIgniter.php:250

Now this seemed to work fine in the earlier project I had been working on. My_Controller.php which extends CI_Controller, is in Core, and my AdminController.php file is in libraries.

abstract class AdminController extends MY_Controller {

public function __construct() {
parent::__construct();
}
}

then my dashboard is in /controllers/accounts/dashboard.php

class Dashboard extends AdminController
{
public function __construct()
{
parent::__construct();
}
}

I must have forgotten to do something, as I can't see any other differences between the two projects related to abstract controllers.
#2

[eluser]pbflash[/eluser]
AdminController.php should also be in the core folder.
#3

[eluser]CroNiX[/eluser]
Edit: missed some stuff.

Read up on this: http://philsturgeon.co.uk/blog/2010/02/C...ing-it-DRY
#4

[eluser]pbflash[/eluser]
[quote author="CroNiX" date="1330477980"]@pbflash, no, it shouldn't. Only direct extensions to the core classes go there (which would be prefixed with MY_). Not controllers that extend them.

AdminController.php should be in /application/controllers, not /application/libraries, since it's actually a controller.[/quote]
I have mine in the core folder and they work. I have MY_Controller which extends CI_Controller and then Public_Controller and Admin_Controller which extend MY_Controller all in the core folder. My controllers then extend Public or Admin. It's working fine but if Public and Admin should be in controllers I'll move them.
#5

[eluser]CroNiX[/eluser]
@pbflash, I apologize, I misread and edited my post. He needs to add a __autoload() magic function for his new extensions to be found like in the blog post of Phils I posted.
#6

[eluser]pbflash[/eluser]
[quote author="CroNiX" date="1330478719"]@pbflash, I apologize, I misread and edited my post. He needs to add a __autoload() magic function for his new extensions to be found like in the blog post of Phils I posted.[/quote]
I was looking for that blog as that is what I used as an example when I was setting mine up.
#7

[eluser]andychurchill[/eluser]
Ah yes, that will be the reason. I was beginning to suspect that in my other project it was related to the HMVC code I'd added with the intention of modularising certain parts of the system, but didn't know the exact reason. Turns out that it contains similar autoload magic, which explains why my sub controller worked in the other project.

Will give this a go, but I suspect this will fix my issue.
#8

[eluser]CroNiX[/eluser]
This is a better __autoload() as it lets you extend libraries the same way.




Theme © iAndrew 2016 - Forum software by © MyBB