Symfony:如何在generator.yml中添加聚合字段?

发布于 2024-10-08 21:11:11 字数 960 浏览 0 评论 0原文

我正在使用 Doctrine 在 Symfony 1.4 中对我的应用程序进行原型设计。我有两个模型,遭遇和照片。一次邂逅可以有很多照片,并且在 schema.yml 中设置了正确的一对多关系。

我使用 ./symfony generated:app backend 生成了一个后端。一切工作正常,但我现在想在我的遭遇列表中添加一个计数字段,我认为我应该能够在生成器.yml 中执行此操作。在我的 Encounters.class.php 中,我有以下方法:

public function getPhotoCount() {

    return count($this->CcPhotos);
}

我的问题是如何在运行此方法的生成器.yml 中添加新字段。我尝试了 %%photo_count%% 但我认为这是用于字符串替换。

generator:
  class: sfDoctrineGenerator
  param:
    model_class:           CcEncounters
    theme:                 admin
    non_verbose_templates: true
    with_show:             false
    singular:              ~
    plural:                ~
    route_prefix:          cc_encounters
    with_doctrine_route:   true
    actions_base_class:    sfActions

config:
  actions: ~
  fields:  ~
  list: ~
  filter:  ~
  form:    ~
  edit:    ~
  new:
    display: [_camera_id, longitude, latitude, elevation, New Photos]

I am prototyping my application in Symfony 1.4 using Doctrine. I have two models, encounters and photos. One encounter can have many photos and the correct one-to-many relationship is set up in schema.yml.

I have generated a backend using ./symfony generate:app backend. Everything is working fine but I now want to add a count field to my encounters list which I think I should be able to do in generator.yml. In my Encounters.class.php I have the following method:

public function getPhotoCount() {

    return count($this->CcPhotos);
}

My questions is how can I add a new field in generator.yml which runs this method. I tried %%photo_count%% but I think this is intended for string substitution.

generator:
  class: sfDoctrineGenerator
  param:
    model_class:           CcEncounters
    theme:                 admin
    non_verbose_templates: true
    with_show:             false
    singular:              ~
    plural:                ~
    route_prefix:          cc_encounters
    with_doctrine_route:   true
    actions_base_class:    sfActions

config:
  actions: ~
  fields:  ~
  list: ~
  filter:  ~
  form:    ~
  edit:    ~
  new:
    display: [_camera_id, longitude, latitude, elevation, New Photos]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁客 2024-10-15 21:11:11

我解决了这个问题。只需添加以下内容即可:

    display: [id, longitude, latitude, elevation, photo_count]

其中 'photo_count' 与名为 getPhotoCount 的访问器方法匹配

I resolved this. It was as simple as adding:

    display: [id, longitude, latitude, elevation, photo_count]

Where 'photo_count' matches an accessor method called getPhotoCount

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文