2011-03-16 49 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