管理生成器:为什么我不能显示文章的状态,而不是 state_id?
我正在 Symfony 中做一个博客引擎。这是我的架构的一部分:
Content:
connection: doctrine
tableName: ec_content
columns:
id:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: true
(...)
relations:
Author:
local: author_id
foreign: id
type: one
State:
local: state_id
foreign: id
type: one
Type:
local: type_id
foreign: id
type: one
(...)
在管理页面中,我想显示文章的类型,但仅限 symfony显示 type_id,这是为什么?
编辑:这是我的generator.yml:我还没有对其进行太多修改。
generator:
class: sfDoctrineGenerator
param:
model_class: Content
theme: admin
non_verbose_templates: true
with_show: false
singular: ~
plural: ~
route_prefix: content_Brouillons
with_doctrine_route: true
actions_base_class: sfActions
config:
actions: ~
fields: ~
list:
title: Brouillons
display: [Type, State, title, link]
filter: ~
form: ~
edit: ~
new: ~
I'm doing a blog engine in Symfony. Here's part of my schema :
Content:
connection: doctrine
tableName: ec_content
columns:
id:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: true
(...)
relations:
Author:
local: author_id
foreign: id
type: one
State:
local: state_id
foreign: id
type: one
Type:
local: type_id
foreign: id
type: one
(...)
In the administration pages, I want to display the type of the articles, but symfony only shows the type_id, why is that ?
EDIT: here's my generator.yml : I haven't modified it much yet.
generator:
class: sfDoctrineGenerator
param:
model_class: Content
theme: admin
non_verbose_templates: true
with_show: false
singular: ~
plural: ~
route_prefix: content_Brouillons
with_doctrine_route: true
actions_base_class: sfActions
config:
actions: ~
fields: ~
list:
title: Brouillons
display: [Type, State, title, link]
filter: ~
form: ~
edit: ~
new: ~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的。
在您的generator.yml中,在
display
行上,Symfony(通过Doctrine)将在您的模型类中查找与您想要显示的每个字段相对应的字段名称。如果字段名称不存在,它将查找相应的 getFieldName() 方法并调用该方法。在您的示例中,您将
Type
作为字段名称,它将调用getType()
- 这将获取关系。默认情况下,Doctrine 假设当您想要要将模型转换为字符串(例如,用于在列表中显示),您需要使用主键 - 在您的情况下,即 ID 值。为了解决这个问题,请在您的 Doctrine
lib/model/doctrine/EcType.class.php
文件中添加一个__toString()
方法,如下所示:您应该看到 'type ' 字段显示在您的管理员生成的列表中。
OK.
In your generator.yml, on the
display
line, Symfony (via Doctrine) will look for a field name in your model class that corresponds to each field you want to display. If the field name doesn't exist, it will then look for a correspondinggetFieldName()
method and call that.In your example, you have
Type
as a field name, which will be callinggetType()
- this will fetch the relation in. By default, Doctrine assumes that when you want to convert a model to a string (eg for display in your list), you want to use the primary key - in your case, the ID value.To overcome this, add a
__toString()
method as follows, to your Doctrinelib/model/doctrine/EcType.class.php
file:and you should see the 'type' field being displayed in your admin generated list.