0
我在symfony中有一個項目,我想讓我的用戶上傳一個圖像作爲他們的「頭像」字段。我已經找到了如何「擴展」的表格很多帖子,我有以下模式:Symfony添加頭像字段到sfGuardUser模型
Member:
inheritance:
type: column_aggregation
extends: sfGuardUser
columns:
idmember: { type: integer }
birthday: { type: date }
avatar: { type: string(255) }
bio: { type: string(255) }
列被添加到表就好了,但是當我去改變窗口小部件,sfWidgetFormInputFileEditable
它休息。這裏是Form.class文件:
$file_src = $this->getObject()->getAvatar();
if ($file_src == '')
{
$file_src = 'default_image.png';
}
$this->widgetSchema['avatar'] = new sfWidgetFormInputFileEditable(array(
'label' => ' ',
'file_src' => '/uploads/avatar/'.$file_src,
'is_image' => true,
'edit_mode' => true,
'template' => '<div>%file%<br />%input%</div>',
));
和 「保存」 的形式的功能:
if($this->isModified())
{
$uploadDir = sfConfig::get('sf_upload_dir');
$thumbnail = new sfThumbnail(150, 150);
$thumbnail2 = new sfThumbnail(800, 800);
if($this->getAvatar())
{
$thumbnail->loadFile($uploadDir.'/avatar/'.$this->getAvatar());
$thumbnail->save($uploadDir.'/avatar/thumbnail/'. $this->getAvatar());
$thumbnail2->loadFile($uploadDir.'/avatar/'.$this->getAvatar());
$thumbnail2->save($uploadDir.'/avatar/big/'. $this->getAvatar());
}
}
當我提交表單,我得到這個錯誤信息:
This form is multipart, which means you need to supply a files array as the bind() method second argument.
我們能否看到「綁定」表單的地方?順便說一下,我認爲'extend'並不是向sfGuardUser添加價值的最佳方式,您是否考慮過將內容添加到sfGuardUser的內置功能? (見[this](http://jmather.com/2010/10/09/customize-sfguarduser-sfdocrineguard/)或[this](http://trac.symfony-project.org/browser/plugins/sfGuardPlugin/分支機構/ 1.3 /自述文件#L225)) – j0k 2013-03-06 08:08:32
j0k感謝您的迴應。我曾嘗試向sfGuardUser添加一個「配置文件」,並且我能夠設置表格,但是如何將額外的字段添加到「註冊」表單中,因此它對用戶而言是無縫的,並且它們都顯示在相同的位置形成?我試着按照這個教程[這裏](http://symfony.com/blog/call-the-expert-customizing-sfdoctrineguardplugin),但它似乎只與後端工作。不是前端「註冊」頁面。我嘗試在sfGuardUserForm.class.php中添加一個「頭像」小部件,但它在表單提交時不會保存任何值。 – djcloud23 2013-03-09 16:21:27
如果您使用'sfGuardRegisterForm',它會擴展'BasesfGuardRegisterForm',它擴展了'sfGuardUserAdminForm'。你的配置文件是在'sfGuardUserAdminForm'中定義的。所以它可能工作。 – j0k 2013-03-09 16:32:22