Symfony 1.4:学说I18N发电机问题
-
30-09-2019 - |
题
我的I18N学说架构和管理器发电机遇到了一个奇怪的问题。
(请先查看下面的编辑部分)
模式看起来像:
CargoSize:
connection: doctrine
actAs:
Timestampable: ~
I18n:
fields: [name, linkname, seoname, description]
tableName: com_cargo_size
columns:
id: { type: integer(11), notnull: true, unsigned: true, primary: true, autoincrement: true }
name: { type: string(50), notnull: true }
linkname: { type: string(100), notnull: true }
seoname: { type: string(100), notnull: true }
description: { type: string(255), notnull: true }
我对sfforms遇到的第一个问题:
new sfWidgetFormDoctrineChoice(array('model' => 'CargoSize', 'expanded' => true, 'multiple' => false), array('style' => 'list-style-type: none; display: inline;'))
这会生成一个带有正确ID的无线电butten设置,但是空名称值。即使我尝试通过直接通过ID和lang选择一个cargosize对象来获得名称值,getName()始终返回一个空字符串(DB正确填充了合适的数据)。
因此,有架构定义是否有些符号?
第二个问题出现在管理员中:
php symfony doc:generate-admin --module=cargo_size admin CargoSize
Generator.yml看起来像:
generator:
class: sfDoctrineGenerator
param:
model_class: CargoSize
theme: admin
non_verbose_templates: true
with_show: false
singular: ~
plural: ~
route_prefix: cargo_size
with_doctrine_route: true
actions_base_class: sfActions
config:
actions: ~
fields: ~
list:
display: [name, lang]
filter: ~
form: ~
edit:
display: [name]
new: ~
有趣的是,列表视图向我显示了I18N名称。但是在编辑视图中,我总是会收到错误 “小部件'名称'不存在”.
你们知道为什么会发生这种情况吗?我会非常感谢您的帮助。
编辑:
我认为问题更深入,因为这种简单的代码和平确实注意到了工作:
首先,数据集用于示例:
cargo_size
id created_at updated_at
1 2010-04-22 21:37:44 2010-04-22 21:37:44
cargo_size_translation
id name linkname seoname description lang
1 klein klein klein klein de
1 small small small small en
$c = Doctrine::getTable('CargoSize')->findOneBy('id', 1);
echo $c; // (toString exists)
// Output: Catchable fatal error: Method CargoSize::__toString()
// must return a string value in
// /var/www/.../apps/frontend/modules/start/templates/indexSuccess.php on line 1
echo $c->getName();
// Output: nothing
有人有任何想法吗?我真的很高兴:(
解决方案 2
我找到了错误。由于某种原因,文化被设定为“de_de“而不是仅仅是“ de”。使用此设置,I18N的行为内容不起作用!
其他提示
第一个问题:
显示的“名称值”取自__ToString()方法结果。您可以添加“方法”选项,例如:
new sfWidgetFormDoctrineChoice(array('model' => 'CargoSize', 'expanded' => true, 'multiple' => false, 'method' => 'getName'), array('style' => 'list-style-type: none; display: inline;'))
第二个问题:
您的表格必须嵌入I18N表格。为此,将其放入配置方法中:
$this->embedI18n($cultures);
$文化是您文化代码的一系列。
不隶属于 StackOverflow