b4rb4ross4 / symfony-user-bundle
提供symfony应用程序用户管理功能的扩展包
dev-master / 1.0.x-dev
2017-09-21 21:28 UTC
Requires
- php: ^7.1
- doctrine/doctrine-bundle: ^1.6
- doctrine/orm: ^2.5
- symfony/symfony: ^3.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-28 20:19:56 UTC
README
步骤 1:下载扩展包
打开命令行控制台,进入您的项目目录,并执行以下命令以下载此扩展包的最新版本(目前还没有稳定版本)
$ composer require b4rb4ross4/symfony-user-bundle "@dev"
此命令要求您全局安装了Composer,具体请参考Composer文档中的安装章节。
步骤 2:启用扩展包
然后,通过将其添加到项目中的app/AppKernel.php文件中已注册的扩展包列表中来启用扩展包
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new B4rb4ross4\UserBundle\UserBundle(), ); // ... } // ... }
步骤 3:配置扩展包
将路由添加到您的app/config/routing.yml
b4rb4ross4_user: resource: '@B4rb4ross4UserBundle/Controller/' type: annotation
最后,您必须更改app/config/security.yml设置
登录路由ID为:b4rb4ross4_user_login,退出路由ID为:b4rb4ross4_user_logout
firewalls: secured_area: # this firewall applies to all URLs pattern: ^/ # but the firewall does not require login on every page # denying access is done in access_control or in your controllers anonymous: ~ # This allows the user to login by submitting a username and password # Reference: https://symfony.com.cn/doc/current/security/form_login_setup.html form_login: # The route name that the login form submits to check_path: b4rb4ross4_user_login # The name of the route where the login form lives # When the user tries to access a protected page, they are redirected here login_path: b4rb4ross4_user_login # Secure the login form against CSRF # Reference: https://symfony.com.cn/doc/current/security/csrf_in_login_form.html csrf_token_generator: security.csrf.token_manager # The page users are redirect to when there is no previous page stored in the # session (for example when the users access directly to the login page). default_target_path: default_route_name logout: # The route name the user can go to in order to logout path: b4rb4ross4_user_logout # The name of the route to redirect to after logging out target: default_route_name
在app/config/config.yml中设置基本视图名称
parameters: b4rb4ross4.user.base_view: backend/base.html.twig
并引入扩展包的config.yml以获取twig变量
imports: - { resource: "@B4rb4ross4UserBundle/Resources/config/config.yml" }