开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜