0

I'm using sfDoctrineGuardPlugin and I'm coming across a small issue.

I have several 'user types', i.e. Admins, Managers, Account Holder.

What I need is to be able to create these users and have specific forms for each type when creating them.

What I'd really like to do, is possibly have a link to something like Create Admin, Create Manager and Create Account Holder, which would like to the form for the user I'm trying to create.

Would I need to create several actions in the plugin to accomodate this, i.e. executeAdmin(), executeManagers and then call a custom form, which my specific widgets configured?

Thanks

terrid25
  • 1,926
  • 8
  • 46
  • 87

2 Answers2

0

You could define those user types as subclasses of the sfGuardUser class. Then, you would have one form for each type, inheriting from sfGuardUserForm.

In your module, either you create an action for each type, if some controler and template code is very specific, or you create a single action, with a test on some parameter to use the correct form class.

Oh, and don't add any code to the plugin. This is a very bad practice. Instead, extends the plugin action in a custom module in your application.

Thibault J
  • 4,336
  • 33
  • 44
  • Ok, so I have created the following forms: `adminForm.class.php`, `managersForm.class.php` and `accountHolderForm.class.php`. All of these extend `sfGuardUserAdminForm`. I have created a `sfGuardUser` admin module and `actions.class.php`, which extends: `sfGuardUserActions extends autoSfGuardUserActions`. Would I then have all my actions for each form in here? Thanks – terrid25 May 03 '11 at 12:52
  • Hi. This is up to you. If only the form and form validation code differ, go with a single action. – Thibault J May 04 '11 at 07:28
0

If you want use admingen, I recommend you to create 3 modules based os sfguarduser model, one per user type.
Then, in each generator.yml you can specify in form block :

form:

class: adminForm (for exemple)

dxb
  • 931
  • 5
  • 7
  • @dxb I have done what you have suggested. The problem is, I am extending the `sfGuardUserProfile`, which in turn extends `sfGuardUserAdminForm`. You can see my forms: http://pastebin.com/fhczEeJt I can't seem to embed the profile form into my user form. Any ideas? – terrid25 May 03 '11 at 14:33
  • All I need is to show all the fields from the `sfGuardUser` table the fields I need from `sfGuardUserProfile` in the `adminForm` – terrid25 May 03 '11 at 14:51
  • In your adminFormProfileForm, it seems you unset all fields of your form... maybe it's the reason why you cannot see the embed profile form in your admin adminForm. – dxb May 03 '11 at 15:07
  • Yes this is because I have 2 forms, `adminForm` and `ManagerForm`. I am unsetting some of the fields as I need some to appear in one form and some fields in the other form. All of the unset'd fields are in the profile table, but not needed for my `adminForm`. Also, in my `generator.yml` file, which form am I calling? `adminForm` or `adminFormProfileForm`? Either one fo them throws an error with invalid widgets. Thanks – terrid25 May 03 '11 at 15:15
  • @dxb do you know why this would be happening? – terrid25 May 03 '11 at 16:13
  • There will be a lot of reasons... Your configuration is hard to reproduce. I have found this old question : [link](http://stackoverflow.com/questions/3934687/embed-forms-in-symfony) In your generator.yml, you must specify adminForm as class form – dxb May 03 '11 at 16:25
  • @dxb I have built the module by extending sfGuardUser model class. I am calling adminForm, which embeds inside the sfGuardUser. I jus't can't seem to save it. – terrid25 May 04 '11 at 10:46
  • I think you have to restart with fresh ideas and code. Try a simple way like this http://stackoverflow.com/questions/3934687/embed-forms-in-symfony and then you have a functional module, try to add complexity. – dxb May 04 '11 at 11:35
  • Well I have pretty much started fomr there. But rather than using the `profileForm`, I need to use differing versions of it, with some widgets enabled and some not. Could I just create several instances that extend `profileForm`? – terrid25 May 04 '11 at 12:42
  • Maybe the use of admingen is not a good idea for your needs. Try to make a standard module, like Thibault J suggests to you, and control display of your widget with form options. – dxb May 04 '11 at 13:08