crisistextline / user-profile-bundle
Crisis Text Line 用户配置文件包
0.0.1
2016-01-13 15:38 UTC
Requires
- php: >=5.3.2
- friendsofsymfony/user-bundle: dev-master
- symfony/form: ~2.3
- symfony/framework-bundle: ~2.3
- symfony/security-bundle: ~2.3
- symfony/twig-bundle: ~2.3
Requires (Dev)
- doctrine/doctrine-bundle: ~1.3
- swiftmailer/swiftmailer: ~4.3|~5
- symfony/validator: ~2.3
- symfony/yaml: ~2.3
This package is not auto-updated.
Last update: 2024-09-25 23:34:15 UTC
README
安装
步骤 1: 下载包
打开命令行,进入项目目录,并执行以下命令以下载此包的最新稳定版本
$ composer require crisistextline/user-profile-bundle
此命令要求您全局安装了Composer,具体请参阅Composer文档中的安装章节。
步骤 2: 启用包
然后,通过将其添加到项目app/AppKernel.php
文件中注册的包列表来启用包
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new CrisisTextLine\UserProfileBundle\CrisisTextLineUserProfileBundle(), ); // ... } // ... }
步骤 3: 添加路由
在app/config/routing.yml
中添加以下路由
crisis_text_line_user_profile: resource: "@CrisisTextLineUserProfileBundle/Controller/" type: annotation prefix: /
步骤 4: 告诉包如何解析用户实体
在app/config/config.yml
中添加以下内容,具体请根据您自己的用户实体类进行设置
doctrine: # ... orm: # ... resolve_target_entities: CrisisTextLine\UserProfileBundle\Model\UserProfileUserInterface: <YourBundle>\Entity\<YourUserEntity>
步骤 5: 向config.yml添加用户角色信息
通过将角色和友好的字符串添加到app/config/config.yml
中,以添加您希望包访问用于访问控制部分和字段的任何特定角色信息
crisis_text_line_user_profile: roles_names: - { role: "ROLE_USER", name: "User" } - { role: "ROLE_SUPER_ADMIN", name: "Super Admin" } # ...
步骤 6: 向用户实体添加UserProfileUserTrait和UserProfileUserInterface
在您的用户类中添加以下内容
<?php // <YourBundle>/User.php // ... use FOS\UserBundle\Model\User as BaseUser; use CrisisTextLine\UserProfileBundle\Entity\UserProfileUserTrait; use CrisisTextLine\UserProfileBundle\Model\UserProfileUserInterface; // ... class User extends BaseUser implements UserProfileUserInterface { use UserProfileUserTrait; // ... }
步骤 7: 运行迁移(如有必要)
如果您使用的是Doctrine Migrations bundle,请通过php app/console doctrine:migrations:diff
创建新的迁移并运行它。否则,根据需要更新数据库。
步骤 8: 覆盖模板
如果您想覆盖基本Twig模板以适应自己的前端环境,请创建一个新的app/Resources/CrisisTextLineUserProfileBundle/views/base.html.twig
,内容如下
{% extends <Your Base Twig Template> %} {% block userprofiles %} {% endblock %}
您可以通过将替换内容放入以下位置来覆盖每个实体的特定模板
app/Resources/CrisisTextLineUserProfileBundle/views/UserProfile
app/Resources/CrisisTextLineUserProfileBundle/views/UserProfileField
步骤 9: 向主模板添加JS
将以下行添加到您的应用程序主模板的<head>
中