Php Symfony管理生成器-显示条令集合

Php Symfony管理生成器-显示条令集合,php,symfony1,symfony-1.4,Php,Symfony1,Symfony 1.4,在我的模型中,我有: * @method Doctrine_Collection getComments() Returns the current record's "Comments" collection <pre> Doctrine_Collection data : Array( ) </pre> 默认情况下,若我生成了管理员,那个么这不会显示在列表中。 如果在generator.yml中: config: actions: ~ fields:

在我的模型中,我有:

 * @method Doctrine_Collection getComments() Returns the current record's "Comments" collection
<pre> Doctrine_Collection data : Array( ) </pre>
默认情况下,若我生成了管理员,那个么这不会显示在列表中。 如果在generator.yml中:

config:
  actions: ~
  fields:  ~
  list:    
    display: [id, title, comments]
  filter:  ~
  form:    ~
  edit:    ~
  new:     ~
那么这个给我看

收集数据:数组() 而不是评论列表

我知道-我可以从缓存中获取文件并显示它,但可能只有使用generator.yml? 例如,如果我有一对多的关系,那么这会显示我这个名字

我不想使用缓存!
谢谢

您可以使用函数解决您的问题

例如,在my
generator.yml

public function getNbQuestions() {
    return $this->getQuestion()->count();
}
nbQuestions是
Object.class.php

  list:
    display: [id, description, public, _comments]

管理生成器将自动调用对象类中的“getYouField”方法。因此,您可以描述一个函数,它为您返回一个长字符串。

除了只显示计数之外,还有其他方法

您可以在generator.yml中添加分部代码:

<?php
  // note that you will need to change the $object
  echo $object->getComments()->count();
?>
<ul>
  <?php foreach($form->getObject()->getComments() as $comment): ?>
    <li><?php echo $comment->getBody() ?></li>
  <?php endforeach; ?>
</ul>
然后在部分(
\u comments.php
)中,您可以调用关系并显示您想要的内容(添加样式、其他信息等):

然后在你的部分:

<?php if(isset($form)): ?>

  <ul>
    <?php foreach($form->getObject()->getComments() as $comment): ?>
      <li><?php echo $comment->getBody() ?></li>
    <?php endforeach; ?>
  </ul>

<?php elseif(isset($object)): ?>

  <?php
    // note that you will need to change the $object
    echo $object->getComments()->count();
  ?>

<?php endif; ?>
<ul>
  <?php foreach($form->getObject()->getComments() as $comment): ?>
    <li><?php echo $comment->getBody() ?></li>
  <?php endforeach; ?>
</ul>
<?php if(isset($form)): ?>

  <ul>
    <?php foreach($form->getObject()->getComments() as $comment): ?>
      <li><?php echo $comment->getBody() ?></li>
    <?php endforeach; ?>
  </ul>

<?php elseif(isset($object)): ?>

  <?php
    // note that you will need to change the $object
    echo $object->getComments()->count();
  ?>

<?php endif; ?>