2012-06-13 43 views
1

我想向sfGuard插件中的用戶表單添加自定義字段。將新用戶字段添加到sfGuard用戶管理員表單

我已經在數據庫中創建了列,併爲該字段添加了widgetschema。它在表單中正確顯示,並且在添加和提交文本時,顯示更新已成功。插入到字段中的數據不會在數據庫中填充。

我想我必須更新sfGuard的模型,因爲它不知道新的字段。我試過$ ./symfony doctrine:build-model,但似乎並沒有更新sfGuard插件中的類。

我已經加入這個sfGuardUserAdminClass:

$this->widgetSchema['department_title'] = new sfWidgetFormInputText(); 
$this->validatorSchema['department_title'] = new sfValidatorString(array()); 

我可以看到的表單字段並提交,它只是沒有趕上和數據插入到數據庫。

UPDATE

我已經更新了我與MYUSER對象架構,遷移的diff和構建的模型。我在sfGuardUserAdminForm.class中添加了$this->embedRelation('Profile');。如果你真的想要一個字段添加到您需要修改的schema.yml配置在plugins/sfDoctrineGuardPlugin/config/doctrine/schema.yml用戶模型,我得到這個錯誤

"Catchable fatal error: Argument 1 passed to sfUser::__construct() must be an instance of sfEventDispatcher, instance of MyUserTable given, called in /Users/careyestes/Sites/sva/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Table.php on line 301 and defined in /Users/careyestes/Sites/sva/lib/vendor/symfony/lib/user/sfUser.class.php on line 46 Fatal error: Call to a member function evictAll() on a non-object in /Users/careyestes/Sites/sva/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1239" 
+0

對不起,也許名稱MyUser是錯誤的,因爲它也是sfUser的默認類的名稱。嘗試在模式中將名稱從MyUser更改爲MyUserProfile。我更新我的答案。 –

回答

1

。找到表sfGuardUser並添加您的列。但是,這並不是好的方式,就像你更新插件一樣,你將會失去你的改變。

最好的辦法是創建一個專用的表格,它將以一對一的關係與sfGuardUser模型鏈接。在你的config /教義/ schema.yml中創建表MyUserProfile:

MyUserProfile: 
    columns: 
    id: { type: integer, primary: true, autoincrement: true } 
    sf_guard_user_id: { type:integer } 
    department_title: { type: string(255) } 
    # ... other column definitions 
    relations: 
    User: 
    class: sfGuardUser 
    foreignType: one 
    foreignAlias: Profile 
    local: sf_guard_user_id 
    onDelete: CASCADE 

重建畢竟自定義屬性將可以訪問通過:

$context->getUser()->getProfile()->getDepartementTitle(); 

而且你可以嵌入產生MyUserProfileForm形式到您的sfGuardUserAdminForm形式:

$this->embedRelation('Profile'); 
+0

我通過更新sfguard模式來實現它。我不知道如果升級,我會失去這些架構設置。我會把這個發展。謝謝。 –

+0

明白了。謝謝。 –

相關問題