disable an application or a module in Symfony
I have two applications. I want to disable one according a field stored in a database. Is possible to disable an application (((if it's not posible) a module) by code maybe using a filter) ? I've found a piece of code that execute开发者_JS百科s the project:disable but i think it's not nice enough.
The alternative I think is to check the value stored in the database inside a custom filter and then redirect to an action that inform 'The site is disabled'.
You can create a filter that checks if the current user may access the requested module/action:
if($this->getRequest()->getParameter('module')=='yourmodule' && !$this->getUser()->mayAccess('yourmodule'()){
//redirect to somewhere else
}
In user class:
function mayAccess($module){
$key = $module.'_enabled';
if(!$this->hasAttribute($key)){
$enabled = ... //Fetch permission from database
$this->setAttribute($key,$enabled);
}
return $this->getAttribute($key);
}
Something like that. Maybe you can use the modules security.yml file and override the function that checks the users credentials and permissions, like the hasCredential() method? That actually seems a more clean way to do it.
See: http://www.symfony-project.org/api/1_4/sfBasicSecurityUser
You could dynamically load only the application you want in your index.php file.
精彩评论