简体   繁体   English

Symfony2存储用户数据的最佳方法?

[英]Symfony2 best way to store user data?

We are in the middle of migrating our web app from using Symfony 1.4 to Symfony 2.5. 我们正在将Web应用程序从使用Symfony 1.4迁移到Symfony 2.5。 One issue I've run across is that the user class does not have a getAttribute os setAttribute method anymore: 我遇到的一个问题是,用户类不再具有getAttribute或setAttribute方法:

$user->getAttribute('regions', array(), 'sfGuardSecurityUser');

This has been deprecated. 不推荐使用。 What would be the best object/method to use to replace this functionality. 什么是取代此功能的最佳对象/方法。 I've thought about using the session to store the variables (mostly ids), but I've read that's a bad idea. 我曾考虑过使用会话来存储变量(主要是ID),但是我读到这是一个坏主意。 I'm also using the FriendsOfSymfony bundle and my User class extends the base class. 我也在使用FriendsOfSymfony捆绑包,而我的User类扩展了基类。

As far as I know the getAttribute and setAttribute methods of symfony 1.4 only store the values to the session so the Symfony 2 equivilent should be: 据我所知,symfony 1.4的getAttribute和setAttribute方法仅将值存储到会话中,因此Symfony 2等效项应为:

$session = $this->container->get('session');

$session->set('name', 'Drak');
$session->get('name');

see: http://symfony.com/doc/current/components/http_foundation/sessions.html 请参阅: http : //symfony.com/doc/current/components/http_foundation/sessions.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM