1

我在管理生成器(Propel 版本)上遇到了一些“问题”。列表视图和表单视图之间的 HTML 生成行为非常不同,我想知道为什么,因为与列表视图相比,表单视图工作得更好(并且符合预期)。

我有以下 YAML 用于“编辑”操作,

edit:
  actions:
    custom: { confirm: 'Run this custom action?' }
    _list:  ~
    _save:  ~

这将为指定的自定义操作生成以下 HTML/PHP,

// Snip ...
<li class="sf_admin_action_custom">
<?php if (method_exists($helper, 'linkToCustom')): ?>
  <?php echo $helper->linkToCustom($form->getObject(), array(  'confirm' => 'Run this custom action?',  'params' =>   array(  ),  'class_suffix' => 'custom',  'label' => 'Custom',)) ?>
<?php else: ?>
  <?php echo link_to(__('Custom', array(), 'messages'), 'users/ListCustom?id='.$user->getId(), array()) ?>
<?php endif; ?>
</li>
// Snip ...

现在,如果我将自定义操作添加到列表视图的 YAML,

list:
  object_actions:
    custom:  { confirm: 'Run this custom action?' }
    _edit:   ~
    _delete: ~

我得到以下 HTML 生成,

// Snip ...
<li class="sf_admin_action_custom">
  <?php echo link_to(__('Custom', array(), 'messages'), 'users/ListCustom?id='.$user->getId(), array()) ?>
</li>
// Snip ...

这里有一些明显的差异,我觉得很奇怪,

  1. 表单操作代码检查帮助器上是否有方法,如果有则使用它,如果没有则回退到标准link_to()函数。但是,列表操作代码仅使用该link_to()函数,甚至没有尝试使用帮助程序。
  2. 表单操作代码将我的自定义确认消息传递给自定义帮助方法,但模板都没有将它传递给link_to(). 为什么是这样?我希望这是一个错误。

如果有人可以阐明为什么两者产生不同的原因,我将非常感激。

谢谢你。

4

1 回答 1

0

管理生成器使用生成上述 HTML/PHP 的模板。默认主题位于:

sfConfig::get('sf_symfony_lib_dir')/plugins/sfPropelPlugin/data/generator/sfPropelModule/admin/. (1.2版)

或者

$sf_symfony_data_dir/generator/sfPropelAdmin/default/(1.0版)

HTML/PHP 代码不同,因为用于生成这些文件的模板不同,但您可以通过创建自己的主题并在 generator.yml 中指定来根据自己的喜好修改它们。例如:

generator:
  class: sfPropelGenerator
  param:
    model_class:           BlogArticle
    theme:                 customTheme

有关如何执行此操作的更多信息,请阅读http://www.symfony-project.org/book/1_2/14-Generators

于 2010-02-10T10:04:46.280 回答