frequence-web/contact-bundle

基于事件的联系组件

安装次数: 12,214

依赖项: 0

建议者: 0

安全性: 0

星标: 4

关注者: 5

分支: 8

开放问题: 4

类型:symfony-bundle

1.0.4 2017-05-23 10:06 UTC

This package is auto-updated.

Last update: 2024-09-21 19:25:05 UTC


README

Build Status

一个基于事件的 Symfony2 联系组件。

安装

使用 composer 安装组件

 $ composer require frequence-web/contact-bundle:1.0.*

将组件添加到您的 AppKernel 类中

    public function registerBundles()
    {
        return array(
            // ... Your bundles
            new \FrequenceWeb\Bundle\ContactBundle\FrequenceWebContactBundle(),
        );
    }

配置

此组件提供了一些配置选项

frequence_web_contact:
    send_mails: true                # True to use the bundle EmailListener that send emails when contact form is submited
    to:         null                # The contact mail recipient
    from:       null                # The contact mail sender
    subject:    contact.message.new # The contact mail subject translation key

路由

如果您想使用默认的组件 URL,只需将路由文件导入到应用程序的路由中

    _frequence_web_contact:
        resource: '@FrequenceWebContactBundle/Resources/config/routing.xml'

这将创建 2 个路由,具有相同的 URL (/contact.html),一个用于显示联系表单(GET),另一个用于提交数据(POST)

创建监听器

如果您想创建一个功能更强大的邮件监听器或其他监听器,您需要定义自己的。成功提交联系表单时触发的事件是 contact.submit,并接收一个 FrequenceWeb\Bundle\ContactBundle\EventDispatcher\Event\MessageSubmitEvent

如果您需要一个示例,请查看 FrequenceWeb\Bundle\ContactBundle\EventDispatcher\Listener\EmailContactListener

扩展

如果您需要更多由 Contact 类和 ContactType 表单类型提供的少量数据,只需覆盖 frequence_web_contact.type.classfrequence_web_contact.model.class 配置参数,它们用于实例化服务,并且可以无限制地扩展。