firediy / private-message-bundle
Symfony FDPrivateMessageBundle
dev-master
2017-10-05 16:45 UTC
Requires
- php: ^5.5.9 || ^7.0
- doctrine/doctrine-bundle: ^1.3
- doctrine/orm: ~2.2,>=2.2.3
- sensio/framework-extra-bundle: ~3.0
- symfony/form: ^2.7 || ^3.0
- symfony/framework-bundle: ^2.7 || ^3.0
- symfony/security-bundle: ^2.7 || ^3.0
- symfony/symfony: ^3.3
- symfony/templating: ^2.7 || ^3.0
- symfony/twig-bundle: ^2.7 || ^3.0
- symfony/validator: ^2.7 || ^3.0
- twig/twig: ^1.28 || ^2.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-26 04:23:42 UTC
README
本插件为用户提供一个会话系统。
要求
- Symfony >= 2.8
- 实现
Symfony\Component\Security\Core\User\UserInterface的用户类
翻译
如果您希望使用此插件中提供的默认文本,请确保您在配置中启用了翻译器。
# app/config/config.yml framework: translator: ~
安装
步骤 1: 使用 composer 下载 FDPrivateMessageBundle
使用 composer 需要此插件
composer require firediy/private-message-bundle dev-master
步骤 2: 启用插件
在内核中启用插件
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new FD\PrivateMessageBundle\FDPrivateMessageBundle(), // ... ); }
步骤 3: 创建您的用户类
本插件的目标是提供一个私人消息系统,以便用户之间进行沟通。FDPrivateMessageBundle 不提供现成的用户实体,而是使用 Symfony 的 UserInterface。
因此,您只需创建一个实现 Symfony\Component\Security\Core\User\UserInterface 的用户类即可。您甚至可以使用 FOSUserBundle。
步骤 4: 配置应用程序的 config.yml
现在您已经有了用户实体,您只需告诉 FDPrivateMessageBundle 使用它
# app/config/config.yml doctrine: orm: resolve_target_entities: Symfony\Component\Security\Core\User\UserInterface: AcmeBundle\Entity\YourUserEntiy
步骤 5: 导入 FDPrivateMessageBundle 路由文件
现在您已经启用并配置了插件,剩下的只是导入 FDPrivateMessageBundle 路由文件。
# app/config/routing.yml fd_private_message: resource: "@FDPrivateMessageBundle/Resources/config/routing.yml"
步骤 6: 更新数据库模式
最后,只需更新您的数据库模式
php bin/console doctrine:schema:update --force
表单
您能够覆盖 FDPrivateMessageBundle 的表单。
例如,如果您使用 FOSUserBundle 并且只想加载未被锁定收件人
use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; use FD\PrivateMessageBundle\Form\ConversationType as BaseType; // Make your form extends FDPrivateMessageBunde::ConversationType. class ConversationType extends BaseType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { // Call parent's builder. parent::buildForm($builder, $options); // Load only users being enabled. $builder->add('recipients', EntityType::class, array( 'class' => 'AcmeBundle:YourUserEntity', 'multiple' => true, 'query_builder' => function(EntityRepository $er) { return $er->createQueryBuilder('u') ->where('u.locked', false); }, )); } }
覆盖默认 FDPrivateMessageBundle 模板
示例:覆盖对话的 show.html.twig 模板
只需在 app/Resources/FDPrivateMessageBundle/views/Conversation/show.html.twig 中创建一个新的文件
<h1>Overridden template</h1> <h2>{{ conversation.subject }}</h2> <ul> {% for message in conversation.messages %} <li> <p>{{ message.author }}, {{ message.created | date('Y-m-d H:i:s') }}</p> <div>{{ message.body | raw }}</div> </li> {% endfor %} </ul>