Page 1 of 1
Change controller directory for admins
Posted: Mon Jan 15, 2007 5:42 pm
by Luke
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?).
Posted: Mon Jan 15, 2007 5:49 pm
by John Cartwright
In your index.php, you could do
Code: Select all
$user = new Zend_Session('user');
if ($user->permission > 0)
{
$controller->setControllerDirectory('Application/Admin/');
}
else
{
$controller->setControllerDirectory('Application/Controller');
}
I personally wouldn't seperate the controllers into two seperate folders.. after all they are all controllers.
Posted: Mon Jan 15, 2007 5:58 pm
by Luke
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.
Posted: Mon Jan 15, 2007 6:05 pm
by John Cartwright
After taking a look at the source,
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;
}
You can pass an array of paths. Enjoy.
Posted: Mon Jan 15, 2007 6:07 pm
by Luke
Thanks!
