我在symfony 2.0中使用自己的User类和安全系统的实体提供程序.
我注意到,每次重新加载页面时,symfony都会从db中获取用户:
SELECT t0.id AS id1,t0.username AS username2,t0.salt AS salt3,t0.password AS password4,t0.email AS email5,t0.is_active AS is_active6,t0.credentials AS credentials7 FROM w9_users t0 WHERE t0.id = ?参数:['23']时间:4.43毫秒
有没有简单的方法来禁用此行为?也许在会话变量中序列化用户数据或以某种方式缓存它们?
我正在关注symfony 2的"如何公开Bundle的语义配置"官方手册.
我有我的configuration.php
namespace w9\UserBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('w9_user');
$rootNode
->children()
->scalarNode('logintext')->defaultValue('Zareejstruj si?')->end()
->end()
;
return $treeBuilder;
}
}
Run Code Online (Sandbox Code Playgroud)
和w9UserExtension.php:
namespace w9\UserBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
class w9UserExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); …Run Code Online (Sandbox Code Playgroud)