2011-03-16 51 views
1

我是Symfony的新手,我甚至没有成功创建有效的模型。Symfony:创建模型时出错

我创造了我的项目 - 它们使用推进 - 写下了以下的schema.yml:

propel: 
    poc: 
    id:   ~ 
    message:  { type: varchar(140), required: true} 
    author:  { type: varchar(255), required: true} 
    plus:   { type: integer, default: 0} 
    minus:  { type: integer, default: 0} 
    created_at: ~ 

然后我执行下面的命令没有错误:

$ php symfony propel:build --sql 
$ php symfony propel:insert-sql 
$ php symfony propel:build --model 

但是当我尝试加载夹具或生成模块,我得到这个错误:

$ php symfony propel:data-load    
>> propel load data from "/home/me/www/poc/data/fixtures" 
PHP Fatal error: Cannot redefine class constant BasePoc::PEER in /home/me/www/poc/lib/model/om/BasePoc.php on line 85 

Fatal error: Cannot redefine class constant BasePoc::PEER in /home/me/www/poc/lib/model/om/BasePoc.php on line 85 

类常量PEER是d在BasePoc.php中定义了两次,但为什么?

我搜索并重新创建了该项目多次,但我看不到我的错误。

+1

有时symfony可能会与基类有点混淆。尝试删除所有Base模型文件所在的整个目录(注意不要删除*您编辑过的任何文件)。这些基础文件在您构建模型时随时生成。如果这不起作用,我会尝试追查类定义的类“PEER”的位置,并检查你是否没有意外地将它添加到类中。 – 2011-03-16 22:32:31

回答

3

,刚读的README文件插件,你错过了最后一步:

Change the path of the symfony behaviors in the config/propel.ini file of your project:

[ini] 
propel.behavior.symfony.class     = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorSymfony 
propel.behavior.symfony_i18n.class    = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorI18n 
propel.behavior.symfony_i18n_translation.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorI18nTranslation 
propel.behavior.symfony_behaviors.class  = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorSymfonyBehaviors 
propel.behavior.symfony_timestampable.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorTimestampable 

注意:文件上的快速“批量替换”就足够了。注2:如果您使用的是sfPropel15Plugin,请升级到sfPropelORMPlugin。

希望它有帮助!

+0

谢谢你,最近更新了很多旧的推进项目,一定是错过了! – Burgi 2011-11-01 12:23:47

+0

对于那些有兴趣使用symfony 1.4 + sfPropelORMPlugin启动新项目的人来说,有一个小小的bash脚本旨在实现这个过程的自动化。 [在这里查看](https://github.com/mppfiles/symfony1-boilerplate)。 – mppfiles 2011-11-18 15:30:48

-1

看来propel无法渲染整个文件。 (propel有非常严重的错误报告,yaml) 请确保检查文件中没有标签,并且所有东西都用2个空格来标识。

其余的对我来说似乎很好。我个人比较喜欢使用的学说,(你会只把created_at参数在ACTAS行为)如果您使用的是新sfPropelORMPlugin而不是用symfony捆绑sfPropelPlugin

proc: 
    actAs: Timestampable: ~ 
    columns: 
    id:   ~ 
    message:  { type: varchar(140), required: true} 
    author:  { type: varchar(255), required: true} 
    plus:   { type: integer, default: 0} 
    minus:  { type: integer, default: 0} 
+0

他使用推动,你给了一个教义模式。 – Maerlyn 2011-03-16 23:06:02

+0

我有Propel 1.5.6的错误,使用Propel 1.4.x解决了这个问题(没有改变schema.yml中的任何东西)。 – 2011-03-17 11:24:07