th3mouk/contact-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

th3mouk/contact-bundle

最新稳定版本:1.2.0

Composer 安装命令:

composer require th3mouk/contact-bundle

包简介

Symfony Th3MoukContactBundle to factorize contact form generation throught websites.

README 文档

README

This Symfony bundle providing base for manage contact form.

The aim is to factorise website contact form.

SensioLabsInsight Latest Stable Version Total Downloads Build Status Latest Unstable Version License

Installation

php composer.phar require th3mouk/contact-bundle ^1.2

Add to the appKernel.php:

new Th3Mouk\ContactBundle\Th3MoukContactBundle(),

Update your routing.yml application's file.

th3mouk_contact:
    resource: "@Th3MoukContactBundle/Resources/config/routing.yml"
    prefix:   /contact

Configure entities and templates in config.yml

th3mouk_contact:
    datas:
        from: noreply@domain.com
        to:
            - test.mail@domain.com
        subject: Contact request from your website
            
    class:
        entity: AppBundle\Entity\Contact
        formType: AppBundle\Form\ContactType

    templates:
        application: AppBundle:Contact:contact.html.twig
        mailer: AppBundle:Contact:mail.html.twig
        
    flash_messages:
        success: contact.mail.success
        error: contact.mail.error

Usage

Create Contact entity that implement the Th3Mouk\ContactBundle\Entity\ContactInterface with the app/console d:g:entity.

Generate the relative FormType: app/console d:g:f AppBundle:Contact.

Create two template for frontend and mail, you have access to form object to draw your form, and your contact object in the mail template.

Check the following exemples:

Exemple of ContactType

namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ContactType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array                $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name')
            ->add('adress')
            ->add('zipCode')
            ->add('city')
            ->add('phone')
            ->add('email', 'email')
            ->add('message')
        ;
    }

    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'AppBundle\Entity\Contact',
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'app_contact_type';
    }
}

Exemple of Form Template

<h1>Contact Request</h1>

{{ form_start(form) }}

{{ form_row(form.name) }}
{{ form_row(form.adress) }}
{{ form_row(form.zipCode) }}
{{ form_row(form.city) }}
{{ form_row(form.phone) }}
{{ form_row(form.email) }}
{{ form_row(form.message) }}

<div class="form-group"><button type="submit" class="btn-default btn">Submit</button></div>

{{ form_rest(form) }}
{{ form_end(form) }}

Exemple of Mail Template

{{ contact.name }}<br>
{{ contact.adress }}<br>
{{ contact.zipCode }}<br>
{{ contact.city }}<br>
{{ contact.phone }}<br>
{{ contact.email }}<br>
{{ contact.message }}

Sonata Integration Exemple

First use the app/console sonata:admin:generate command.

Then add the service configuration:

app.admin.contact:
    class: AppBundle\Admin\ContactAdmin
    arguments: [~, AppBundle\Entity\Contact, SonataAdminBundle:CRUD]
    tags:
        - {name: sonata.admin, manager_type: orm, label: Contacts}

Add the admin group on the dashboard:

sonata.admin.group.contact:
    label:           Contact
    label_catalogue: SonataPageBundle
    icon:            '<i class="fa fa-envelope"></i>'
    items:
        - app.admin.contact
    roles: [ ROLE_ADMIN ]

Don't forget to add this group on a block:

sonata_admin:
    dashboard:
        blocks:
            - { position: left, type: sonata.admin.block.admin_list, settings: { groups: [...sonata.admin.group.contact...] }}

You're done! 👍

Events

You have access to two events before and after mail was send :

Please

Feel free to improve this bundle.

统计信息

  • 总下载量: 280
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-07