21278 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 224 Views |
-
Extending a Controller that extends Page_Controller

1 December 2011 at 5:07am Last edited: 1 December 2011 6:04am
Hi,
Perhaps I'm missing something obvious, but I'm trying to extend a Controller class that extends Page_Controller. So for example
Class ForumHolder_Controller extends Page_Controller{
function init(){
parent::init();
}
}and then I have:
class ForumHolderExtension_Controller extends ForumHolder_Controller{
function init(){
parent::init();
Requirements::CSS('themes/'. SSViewer::current_theme() .'/css/test.css');
}
}my test.css will not be included on the page. Is this possible?
In the end what I am trying to accomplish is in my ForumHolderExtension_Controller I want to add some Permission:: checks to the init function. Is there an alternative approach to solving this?
Thank you.
-
Re: Extending a Controller that extends Page_Controller

1 December 2011 at 7:11am
I managed to get something working, but I'm not sure if this is the best approach - here is my code.
class ForumHolder_Controller extends Page_Controller{
function init(){
parent::init();
$allowed = true;
$this->extend('updateInit', $allowed);
if($allowed){
//do nothing
} else {
Security::permissionFailure($this);
}
}
}and the extension:
class ForumHolderExtension_Controller extends Extension{
function updateInit(&$allowed){
//checking permission using custom PlanPermission class
$allowed = PlanPermission::check('FORUM_VIEW');
return $allowed;
}
}and of course in my _config.php I have:
Object::extension('ForumHolder_Controller', 'ForumHolderExtension_Controller');
This works, if I'm signed in as a member with the proper permissions I can view the page, and members without the proper permissions are blocked. One problem though is that if i'm signed in as a member without proper permissions I get a white screen, but if I'm not signed in I get the SS login form.
| 224 Views | ||
|
Page:
1
|
Go to Top |

