segunda-feira, 21 de junho de 2010

Sobre sfUser

O melhor link que achei na internet sobre como acessar sfUser das diferentes partes do symfony:
http://erisds.co.uk/symfony/snippet-symfony-user-access-the-user-object

Resumidamente é

Template / View:
$user = $sf_user;

Model ou Form:
$user = sfContext::getInstance()->getUser();

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’.

Action:
$user = $this->getUser();
ou
$user = sfContext::getInstance()->getUser();


sfGuardUser and sfGuardUserProfile

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:

Template / View
$profile = $user->getGuardUser()->getProfile();

A Note on Snippets: When using frameworks such as Symfony it is often the simplest pieces of code which are the hardest to either find or remember. These snippets are placed here for my own reference and will hopefully be useful to others. If you find them useful or have any suggestions, please let me know.

domingo, 20 de junho de 2010

Ocultando backend.php da URL

Ainda não cheguei a nenhuma conclusão nem solução definitiva sobre isso, mas ficam aqui dois links para dar uma lida e implementar com cuidado em uma outra aplicação que não esteja em produção.
Eu tinha desenvolvido uma, mas não foi satisfatória então saí catando na internet. Achei duas prováveis soluções. Tentei aplicar as duas, mas não deu muito certo.

Verificar depois o porquê (com mais paciência e sem o deadline estourado).

Links:
1. http://jonocode.wordpress.com/2009/09/30/giving-your-symfony-apps-better-urls/
2. http://particul.es/blog/index.php?post/How-to-change-backend.php-to-admin-prefix-routes-automatically-symfony