symfony 1.0: launch Admin Generator from Action or Component

/ Published in: PHP
Save to your folder(s)

This snippet is useful if you want to include partials of another admin generated module into the current one (at runtime). This is necessary to *always* make sure that the partial is available, even after clearing the cache. And this is not always true. E.g. you're clearing automatically or manually the cache and the partial isn't overridden/existent in the other module's templates directory.

Copy this code and paste it in your HTML
  1. // make sure, that the other module was already generated
  2. try
  3. {
  4. // try to initialize a partial view of the offer module
  5. $view = new sfPartialView();
  6. // this will throw an exception if the partial doesn't exist
  7. $view->initialize($this->getContext(), 'my_module', '_list_td_actions', '');
  8. // call the render() method in order to provoke an exception, so we can generate the module parts
  9. $retval = $view->render(array('my_module' => new SampleModelObject()));
  10. // unset the view object to save memory
  11. unset($view);
  12. }
  13. // catch the exception, fire the admin generator for the offer module, it's neccessary here!
  14. catch (Exception $e)
  15. {
  16. // dividing sf_app_dir and sf_app_module_dir_name is neccessary,
  17. // because sfGeneratorConfigHandler will make a regexp match like /[moduleName]/
  18. // to determine the correct module and pass it to sfCrudGenerator
  19. // therefore, we cant use the sf_app_module_dir setting, because in windows the regexp will not match
  20. $path = array(
  21. sfConfig::get('sf_app_dir'),
  22. sfConfig::get('sf_app_module_dir_name'),
  23. 'my_module',
  24. sfConfig::get('sf_app_module_config_dir_name'),
  25. 'generator.yml'
  26. );
  27. include(sfConfigCache::getInstance()->checkConfig(implode('/', $path)));
  28. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.