Guest User

Untitled

a guest
Jul 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. ## apps/frontend/config/factories.yml
  2.  
  3. all:
  4. controller:
  5. class: mySfFrontWebController
  6.  
  7.  
  8. ## apps/frontend/config/app.yml
  9.  
  10. all:
  11. database_not_connected:
  12. module: main
  13. action: notconnected
  14.  
  15.  
  16. ## apps/frontend/config/frontendConfiguration.class.php
  17.  
  18. class frontendConfiguration extends sfApplicationConfiguration
  19. {
  20. public function configure()
  21. {
  22. $this->dispatcher->connect('doctrine.configure_connection', array($this, 'listenToAddCheckDatabaseConnection'));
  23. }
  24.  
  25. public function listenToAddCheckDatabaseConnection(sfEvent $event)
  26. {
  27. $actions = $event->getSubject();
  28. sfConfig::set('sf_database_is_connected', $actions->getCurrentConnection()->isConnected());
  29. }
  30.  
  31. }
  32.  
  33.  
  34. ## lib/controller/mySfFrontWebController.class.php
  35.  
  36. class mySfFrontWebController extends sfFrontWebController
  37. {
  38. public function dispatch()
  39. {
  40. if (!sfConfig::get('sf_database_is_connected', true))
  41. {
  42. $request = $this->context->getRequest();
  43. $moduleName = $request->getParameter('module');
  44. $actionName = $request->getParameter('action');
  45.  
  46. if ((!$module = sfConfig::get('app_database_not_connected_module')) ||
  47. (!$action = sfConfig::get('app_database_not_connected_action')))
  48. {
  49. throw new sfConfigurationException('Missing parameters app_database_not_connected_module and/or app_database_not_connected_action in app.yml');
  50. }
  51. else
  52. {
  53. if (($moduleName != $module) && ($actionName != $action))
  54. {
  55. $this->forward($module, $action);
  56. exit;
  57. }
  58. }
  59. }
  60. parent::dispatch();
  61. }
  62. }
Add Comment
Please, Sign In to add comment