tangoman / user-bundle
Symfony 用户组件包
1.0.6
2018-04-08 21:29 UTC
Requires
- php: >=5.3.0
- tangoman/entity-helper: ^2.0
- tangoman/jwt-bundle: ^1.0
README
TangoMan 用户组件包 提供用户管理的基础。
安装
步骤 1: 下载组件包
打开命令行,进入您的项目目录,并执行以下命令以下载此组件包的最新稳定版本
$ composer require tangoman/user-bundle
此命令要求您全局安装了 Composer,如 Composer 文档的 安装章节 所述。
步骤 2: 启用组件包
然后,通过将其添加到项目 app/AppKernel.php 文件中注册的组件包列表中启用组件包。
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { // ... public function registerBundles() { $bundles = array( // ... new TangoMan\UserBundle\TangoManUserBundle(), ); // ... } }
步骤 3: 配置 UserBundle 路由
通过在项目 app/config/routing.yml 文件中添加以下代码启用 UserBundle 控制器。
tangoman_user: resource: "@TangoManUserBundle/Controller/" type: annotation
步骤 4: 配置 Symfony 防火墙
通过在项目 app/config/security.yml 文件中添加以下代码启用 UserBundle 处理用户登录/登出。
security: firewalls: admin: anonymous: ~ provider: database pattern: ^/ form_login: login_path: app_login check_path: app_check default_target_path: homepage logout: path: app_logout target: homepage invalidate_session: true
步骤 5: 配置 UserBundle 参数
UserBundle 需要这些设置来处理用户注册、密码重置邮件。
在项目 app/config/parameters.yml 文件中添加以下代码。
parameters: site_name: "FooBar" site_author: "TangoMan" mailer_from: "tangoman@localhost.dev"
步骤 6: 更新 Twig 配置
通过在项目 app/config/config.yml 文件中添加以下代码启用 twig 处理全局变量。
# Twig Configuration twig: globals: site_name: "%site_name%" site_author: "%site_author%" mailer_from: "%mailer_from%"
步骤 7: 创建用户实体
您的用户实体必须扩展 TangoMan\UserBundle\Model\User 类。
您的用户实体必须实现 getRoles() 方法。
<?php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use TangoMan\UserBundle\Model\User as TangoManUser; /** * Class User * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") * @ORM\Table(name="user") */ class User extends TangoManUser { // ... private $roles; public function __construct() { parent::__construct(); // ... } public function getRoles() { return $this->roles; } }
步骤 8: 基础模板
您的基模板必须命名为以下名称: base.html.twig
注意
如果您发现任何错误,请在此处报告:问题
许可协议
版权所有 (c) 2018 Matthias Morin
如果您喜欢 TangoMan 用户组件包,请给它加星标!并在 GitHub 上关注我:TangoMan75 ... 还可以查看我的其他有趣项目。