Return to Snippet

Revision: 23807
at February 13, 2010 17:37 by dreadwarrior


Updated Code
// make sure, that the other module was already generated
try
{
  // try to initialize a partial view of the offer module
  $view = new sfPartialView();
  // this will throw an exception if the partial doesn't exist
  $view->initialize($this->getContext(), 'my_module', '_list_td_actions', '');
  // call the render() method in order to provoke an exception, so we can generate the module parts
  $retval = $view->render(array('my_module' => new SampleModelObject()));
  // unset the view object to save memory
  unset($view);
}
// catch the exception, fire the admin generator for the offer module, it's neccessary here!
catch (Exception $e)
{
  // dividing sf_app_dir and sf_app_module_dir_name is neccessary,
  // because sfGeneratorConfigHandler will make a regexp match like /[moduleName]/
  // to determine the correct module and pass it to sfCrudGenerator
  // therefore, we cant use the sf_app_module_dir setting, because in windows the regexp will not match
  $path = array(
    sfConfig::get('sf_app_dir'),
    sfConfig::get('sf_app_module_dir_name'),
    'my_module',
    sfConfig::get('sf_app_module_config_dir_name'),
    'generator.yml'
  );
  include(sfConfigCache::getInstance()->checkConfig(implode('/', $path)));
}

Revision: 23806
at February 13, 2010 17:33 by dreadwarrior


Initial Code
// have to make sure, that the offer module was already generated
    try
    {
      // try to initialize a partial view of the offer module
      $view = new sfPartialView();
      // this will throw an exception if the partial doesn't exist
      $view->initialize($this->getContext(), 'offer', '_list_td_actions', '');
      // we must call the render() method in order to provoke an exception, so we can generate the offer module parts
      $retval = $view->render(array('offer' => new Offer()));
      // unset the view object to save memory
      unset($view);
    }
    // catch the exception, fire the admin generator for the offer module, it's neccessary here!
    catch (Exception $e)
    {
      // dividing sf_app_dir and sf_app_module_dir_name is neccessary,
      // because sfGeneratorConfigHandler will make a regexp match like /[moduleName]/
      // to determine the correct module and pass it to sfCrudGenerator
      // therefore, we cant use the sf_app_module_dir setting, because in windows the regexp will not match
      $path = array(
        sfConfig::get('sf_app_dir'),
        sfConfig::get('sf_app_module_dir_name'),
        'offer',
        sfConfig::get('sf_app_module_config_dir_name'),
        'generator.yml'
      );
      include(sfConfigCache::getInstance()->checkConfig(implode('/', $path)));
    }

Initial URL


Initial Description
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.

Initial Title
symfony 1.0: launch Admin Generator from Action or Component

Initial Tags
php

Initial Language
PHP