我有一个叫做Users的模块,它允许我创建用户。但是,我也有一个名为Profiles的模型。它与用户不同,但每当我创建一个新用户时,我想添加一个新的配置文件。另外,我想在配置文件表中添加两个字段,在用户窗体中可用。你们有没有想过在Symfony中如何做到这一点?Symfony 1.4和在一个表单上编辑/创建多个模型?
0
A
回答
0
看看sfdoctrineapply他们几乎完全符合你的要求。
或详细
#schema for the profile
sfGuardUserProfile:
tableName: sf_guard_user_profile
columns:
id:
type: integer(4)
primary: true
autoincrement: true
user_id:
type: integer(4)
notnull: true
email:
type: string(80)
fullname:
type: string(80)
validate:
type: string(17)
# Don't forget this!
relations:
User:
class: sfGuardUser
foreign: id
local: user_id
type: one
onDelete: cascade
foreignType: one
foreignAlias: Profile
,并在您的表单,您创建用户:
public function doSave($con = null)
{
$user = new sfGuardUser();
$user->setUsername($this->getValue('username'));
$user->setPassword($this->getValue('password'));
// They must confirm their account first
$user->setIsActive(false);
$user->save();
$this->userId = $user->getId();
return parent::doSave($con);
}
0
首先你必须创建表单文件夹中的自定义表单。在此表单中添加创建用户所需的所有字段。然后,你必须改变你的processForm方法(或者你可以做到这一点,显示形式瓶暗示方法内)
protected function processForm(sfWebRequest $request, sfForm $form){
$form->bind($request->getParameter('registration'));
if ($form->isValid())
{
$user= new sfGuardUser();
$user->setUsername($form->getValue('username'));
$user->setPassword($form->getValue('password'));
$user->setIsActive(true);
$user->save();
$profile= new sfGuardUserProfile();
$profile->setUserId($user->getId());
$profile->setName($form->getValue('nombre'));
$profile->setSurname($form->getValue('apellidos'));
$profile->setMail($form->getValue('username'));
$profile->save();
$this->redirect('@user_home');
}
}
0
相关问题
- 1. Django的 - 创建表单编辑模型的多个实例
- 2. Symfony 1.4教条创建表
- 3. 一个表单和多个模型
- 4. Symfony:多个模型的单一视图
- 5. 相同的自定义表单编辑和创建页面symfony
- 6. 用一种形式创建具有多个模型的可编辑模板
- 7. 动态创建一个可编辑表
- 8. 创建一个可编辑的HTML表
- 9. 在另一个视图页上编辑一个模型 - ASP.NET MVC
- 10. symfony的1.4 - 理论 - 在模型模式
- 11. 如何在symfony中使用多种表单类型创建一个带有数据类的单一表单
- 12. 编辑另一个模型创建实例
- 13. 我可以在symfony中为同一个模型类做多个表单吗?
- 14. Rails:显示从一个模型创建表单到另一个模型视图
- 15. Django表单模型和编辑
- 16. 一次性创建多个模型
- 17. 创建多个模型 - 一类的Rails
- 18. 创建一个简单的表单应用程序来编辑一个文本
- 19. 使用两个独立模型在ASP.NET上创建表单
- 20. 如何在Symfony中使用FOSUserBundle创建多个登录表单
- 21. Mysql为同一个模式类型创建一个表名称多个表
- 22. Django使用一个模板创建和编辑页面
- 23. Symfony 1.4 sfWidgetFormInputFile可编辑自定义
- 24. jQuery:jqGrid - 创建一个可以编辑单元格的表格
- 25. 在CakePHP中创建一个与模型无关的表单
- 26. 编辑多个模型蛋糕PHP
- 27. django:如何从包含外键的多个模型中创建一个表单
- 28. 如何在CakePHP的单个页面上创建多个表单?
- 29. 在一个页面上跨多个表单拆分一个视图模型
- 30. symfony 1.4使用AJAX在另一个子表单中嵌入子表单