Change controller directory for admins
Moderator: General Moderators
Change controller directory for admins
I'm building an application within the Zend Framework. Within my application, if you are an admin you have access to the administration panel, which is separate from the application (like phpbb's). What I want to know, is how I would tell the controller object to load its controllers from the controllers/admin directory if the user is logged in as an administrator. Should I write a plugin? Should I abstract the Action Class? (I've already done so for other reasons, but should I put the functionality in there somewhere?).
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
In your index.php, you could do
I personally wouldn't seperate the controllers into two seperate folders.. after all they are all controllers.
Code: Select all
$user = new Zend_Session('user');
if ($user->permission > 0)
{
$controller->setControllerDirectory('Application/Admin/');
}
else
{
$controller->setControllerDirectory('Application/Controller');
}The only reason I want to is so that I can tell at a glance (in the directory) which controllers are for admins and which are just users. Is there a better way to accomplish what I want?
By the way, I had thought of that method you posted, but it feels like there should be a better way. Thank you. I'll just do that.
By the way, I had thought of that method you posted, but it feels like there should be a better way. Thank you. I'll just do that.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
After taking a look at the source,
You can pass an array of paths. Enjoy.
Code: Select all
public function setControllerDirectory($path)
{
$dirs = (array) $path;
foreach ($dirs as $key => $dir) {
if (!is_dir($dir) or !is_readable($dir)) {
throw new Zend_Controller_Dispatcher_Exception("Directory \"$dir\" not found or not readable");
}
$dirs[$key] = rtrim($dir, '/\\');
}
$this->_directories = $dirs;
return $this;
}