Changeset 12758
- Timestamp:
- 11/08/08 11:35:24 (1 year ago)
- Files:
-
- plugins/sfPropelPlugin/trunk/data/generator/sfPropelModule/admin/template/templates/_filters.php (modified) (2 diffs)
- plugins/sfPropelPlugin/trunk/data/generator/sfPropelModule/admin/template/templates/_list_th_tabular.php (modified) (1 diff)
- plugins/sfPropelPlugin/trunk/data/generator/sfPropelModule/admin/template/templates/indexSuccess.php (modified) (1 diff)
- plugins/sfPropelPlugin/trunk/lib/task/sfPropelGenerateAdminTask.class.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelPlugin/trunk/data/generator/sfPropelModule/admin/template/templates/_filters.php
r12647 r12758 4 4 [?php endif; ?] 5 5 6 <form action="[?php echo url_for(' @<?php echo $this->getUrlForAction('filter') ?>') ?]" method="post">6 <form action="[?php echo url_for('<?php echo $this->getUrlForAction('collection') ?>', array('action' => 'filter')) ?]" method="post"> 7 7 <table cellspacing="0"> 8 8 <tfoot> … … 10 10 <td colspan="2"> 11 11 [?php echo $form->renderHiddenFields() ?] 12 [?php echo link_to(__('Reset', array(), 'sf_admin'), ' @<?php echo $this->getUrlForAction('filter') ?>', array('method' => 'post', 'query_string' => '_reset')) ?]12 [?php echo link_to(__('Reset', array(), 'sf_admin'), '<?php echo $this->getUrlForAction('collection') ?>', array('action' => 'filter'), array('query_string' => '_reset', 'method' => 'post')) ?] 13 13 <input type="submit" value="[?php echo __('Filter', array(), 'sf_admin') ?]" /> 14 14 </td> plugins/sfPropelPlugin/trunk/data/generator/sfPropelModule/admin/template/templates/_list_th_tabular.php
r12474 r12758 4 4 <?php if ($field->isReal()): ?> 5 5 [?php if ('<?php echo $name ?>' == $sort[0]): ?] 6 [?php echo link_to(__('<?php echo $field->getConfig('label') ?>', array(), '<?php echo $this->getI18nCatalogue() ?>'), '<?php echo $this->get ModuleName() ?>/index?sort=<?php echo $name ?>&sort_type='.($sort[1] == 'asc' ? 'desc' : 'asc')) ?]6 [?php echo link_to(__('<?php echo $field->getConfig('label') ?>', array(), '<?php echo $this->getI18nCatalogue() ?>'), '<?php echo $this->getUrlForAction('list') ?>', array(), array('query_string' => 'sort=<?php echo $name ?>&sort_type='.($sort[1] == 'asc' ? 'desc' : 'asc'))) ?] 7 7 <img src="[?php echo sfConfig::get('sf_admin_module_web_dir').'/images/'.$sort[1].'.png' ?]" alt="[?php echo __($sort[1], array(), 'sf_admin') ?]" /> 8 8 [?php else: ?] 9 [?php echo link_to(__('<?php echo $field->getConfig('label') ?>', array(), '<?php echo $this->getI18nCatalogue() ?>'), '<?php echo $this->get ModuleName() ?>/index?sort=<?php echo $name ?>&sort_type=asc') ?]9 [?php echo link_to(__('<?php echo $field->getConfig('label') ?>', array(), '<?php echo $this->getI18nCatalogue() ?>'), '<?php echo $this->getUrlForAction('list') ?>', array(), array('query_string' => 'sort=<?php echo $name ?>&sort_type=asc')) ?] 10 10 [?php endif; ?] 11 11 <?php else: ?> plugins/sfPropelPlugin/trunk/data/generator/sfPropelModule/admin/template/templates/indexSuccess.php
r12493 r12758 19 19 <div id="sf_admin_content"> 20 20 <?php if ($this->configuration->getValue('list.batch_actions')): ?> 21 <form action="[?php echo url_for('<?php echo $this->getUrlForAction(' batch') ?>') ?]" method="post">21 <form action="[?php echo url_for('<?php echo $this->getUrlForAction('collection') ?>', array('action' => 'batch')) ?]" method="post"> 22 22 <?php endif; ?> 23 23 [?php include_partial('<?php echo $this->getModuleName() ?>/list', array('pager' => $pager, 'sort' => $sort, 'helper' => $helper)) ?] plugins/sfPropelPlugin/trunk/lib/task/sfPropelGenerateAdminTask.class.php
r12474 r12758 28 28 $this->addArguments(array( 29 29 new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'), 30 new sfCommandArgument('route ', sfCommandArgument::REQUIRED, 'The route name'),30 new sfCommandArgument('route_or_model', sfCommandArgument::REQUIRED, 'The route name or the model class'), 31 31 )); 32 32 33 33 $this->addOptions(array( 34 new sfCommandOption('module', null, sfCommandOption::PARAMETER_REQUIRED, 'The module name', null), 34 35 new sfCommandOption('theme', null, sfCommandOption::PARAMETER_REQUIRED, 'The theme name', 'admin'), 35 36 new sfCommandOption('singular', null, sfCommandOption::PARAMETER_REQUIRED, 'The singular name', null), … … 45 46 The [propel:generate-admin|INFO] task generates a Propel admin module: 46 47 48 [./symfony propel:generate-admin frontend Article|INFO] 49 50 The task creates a module in the [%frontend%|COMMENT] application for the 51 [%Article%|COMMENT] model. 52 53 The task creates a route for you in the application [routing.yml|COMMENT]. 54 55 You can also generate a Propel admin module by passing a route name: 56 47 57 [./symfony propel:generate-admin frontend article|INFO] 48 58 … … 50 60 [%article%|COMMENT] route definition found in [routing.yml|COMMENT]. 51 61 52 For the filters to work properly, you need to add a collection route for it: 62 For the filters and batch actions to work properly, you need to add 63 collection routes for them: 53 64 54 article s:65 article: 55 66 class: sfPropelRouteCollection 56 67 options: 57 68 model: Article 58 module: article 59 collection_actions: { filter: post } 60 69 collection_actions: { filter: post, batch: post } 61 70 EOF; 62 71 } … … 68 77 { 69 78 // get configuration for the given route 70 $config = new sfRoutingConfigHandler(); 71 $routes = $config->evaluate($this->configuration->getConfigPaths('config/routing.yml')); 79 if (false !== $this->getRouteFromName($arguments['route_or_model'])) 80 { 81 $arguments['route'] = $routes[$arguments['route_or_model']]; 82 $arguments['route_name'] = $arguments['route_or_model']; 72 83 73 if (!isset($routes[$arguments['route']])) 74 { 75 throw new sfCommandException(sprintf('The route "%s" does not exist.', $arguments['route'])); 84 return $this->generateForRoute($arguments, $options); 76 85 } 77 86 78 $routeOptions = $routes[$arguments['route']]->getOptions(); 87 // is it a model class name 88 if (!class_exists($arguments['route_or_model'])) 89 { 90 throw new sfCommandException(sprintf('The route "%s" does not exist and there is no "%s" class.', $arguments['route_or_model'])); 91 } 79 92 80 if (!$routes[$arguments['route']] instanceof sfPropelRouteCollection) 93 $r = new ReflectionClass($arguments['route_or_model']); 94 if (!$r->isSubclassOf('BaseObject')) 81 95 { 82 throw new sfCommandException(sprintf('The route "%s" is not a Propel collection route.', $arguments['route'])); 96 throw new sfCommandException(sprintf('"%s" is not a Propel class.', $arguments['route_or_model'])); 97 } 98 99 // create a route 100 $model = $arguments['route_or_model']; 101 $name = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), '\\1_\\2', $model)); 102 103 $routing = sfConfig::get('sf_app_config_dir').'/routing.yml'; 104 $content = file_get_contents($routing); 105 $routesArray = sfYaml::load($content); 106 107 if (!isset($routesArray[$name])) 108 { 109 $module = $options['module'] ? $options['module'] : $name; 110 $content = sprintf(<<<EOF 111 %s: 112 class: sfPropelRouteCollection 113 options: 114 model: %s 115 module: %s 116 prefix_path: %s 117 with_wilcard_routes: true 118 119 120 EOF 121 , $name, $model, $module, $module).$content; 122 123 file_put_contents($routing, $content); 124 } 125 126 $arguments['route'] = $this->getRouteFromName($name); 127 $arguments['route_name'] = $name; 128 129 return $this->generateForRoute($arguments, $options); 130 } 131 132 protected function generateForRoute($arguments, $options) 133 { 134 $routeOptions = $arguments['route']->getOptions(); 135 136 if (!$arguments['route'] instanceof sfPropelRouteCollection) 137 { 138 throw new sfCommandException(sprintf('The route "%s" is not a Propel collection route.', $arguments['route_name'])); 83 139 } 84 140 … … 113 169 return $task->run(array($arguments['application'], $module, $model), $taskOptions); 114 170 } 171 172 protected function getRouteFromName($name) 173 { 174 $config = new sfRoutingConfigHandler(); 175 $routes = $config->evaluate($this->configuration->getConfigPaths('config/routing.yml')); 176 177 if (isset($routes[$name])) 178 { 179 return $routes[$name]; 180 } 181 182 return false; 183 } 115 184 }

