Acceso al objeto usuario
Versión 1 (Guillermo Zdanowicz, 25/04/2013 23:53)
| 1 | 1 | Guillermo Zdanowicz | h1. Acceso al objeto usuario |
|---|---|---|---|
| 2 | 1 | Guillermo Zdanowicz | |
| 3 | 1 | Guillermo Zdanowicz | |
| 4 | 1 | Guillermo Zdanowicz | Template / View |
| 5 | 1 | Guillermo Zdanowicz | |
| 6 | 1 | Guillermo Zdanowicz | $user = $sf_user; |
| 7 | 1 | Guillermo Zdanowicz | |
| 8 | 1 | Guillermo Zdanowicz | Model or Form |
| 9 | 1 | Guillermo Zdanowicz | |
| 10 | 1 | Guillermo Zdanowicz | $user = sfContext::getInstance()->getUser(); |
| 11 | 1 | Guillermo Zdanowicz | Note: the context isn’t setup when using the command line, therefore if you use this in the save() method of an object and try to populate the object from a data-load it will throw an error: ‘The “default” context does not exist’. |
| 12 | 1 | Guillermo Zdanowicz | |
| 13 | 1 | Guillermo Zdanowicz | Action |
| 14 | 1 | Guillermo Zdanowicz | |
| 15 | 1 | Guillermo Zdanowicz | $user = $this->getUser(); |
| 16 | 1 | Guillermo Zdanowicz | or |
| 17 | 1 | Guillermo Zdanowicz | $user = sfContext::getInstance()->getUser(); |
| 18 | 1 | Guillermo Zdanowicz | sfGuardUser and sfGuardUserProfile |
| 19 | 1 | Guillermo Zdanowicz | |
| 20 | 1 | Guillermo Zdanowicz | sfGuard is a popular plugin for Symfony which provides a complete set of tools for managing users, groups, permissions and profiles. Once the user object has been retrieved as above, the sfGuard user and profile are accessed as follows: |
| 21 | 1 | Guillermo Zdanowicz | |
| 22 | 1 | Guillermo Zdanowicz | Template / View |
| 23 | 1 | Guillermo Zdanowicz | |
| 24 | 1 | Guillermo Zdanowicz | $profile = $user->getGuardUser()->getProfile(); |