mremi/contact-bundle
Composer 安装命令:
composer require mremi/contact-bundle
包简介
Implementation of a contact form for Symfony2
README 文档
README
This bundle provides a contact form in Symfony2.
License
This bundle is available under the MIT license.
Prerequisites
This version of the bundle requires Symfony 2.3+.
Translations
If you wish to use default texts provided in this bundle, you have to make sure you have translator enabled in your config.
# app/config/config.yml framework: translator: ~
For more information about translations, check the Symfony documentation.
Installation
Installation is a quick 6 step process:
- Download MremiContactBundle using composer
- Enable the Bundle
- Create your Contact class (optional)
- Configure the MremiContactBundle
- Import MremiContactBundle routing
- Update your database schema (optional)
Step 1: Download MremiContactBundle using composer
Add MremiContactBundle in your composer.json:
{ "require": { "mremi/contact-bundle": "dev-master" } }
Now tell composer to download the bundle by running the command:
$ php composer.phar update mremi/contact-bundle
Composer will install the bundle to your project's vendor/mremi directory.
Step 2: Enable the bundle
Enable the bundle in the kernel:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Mremi\ContactBundle\MremiContactBundle(), ); }
Step 3: Create your Contact class (optional)
The goal of this bundle is not to persist some Contact class to a database,
but you can if you want just by setting the store_data parameter to true
(default false).
So if you don't need to do this, you can jump to the next step.
Your first job, then, is to create the Contact class for your application.
This class can look and act however you want: add any properties or methods you
find useful. This is your Contact class.
The bundle provides base classes which are already mapped for most fields to make it easier to create your entity. Here is how you use it:
- Extend the base
Contactclass from theEntityfolder - Map the
idfield. It must be protected as it is inherited from the parent class.
Note:
For now, only Doctrine ORM is handled by this bundle (any PR will be appreciated :) ).
<?php // src/Acme/ContactBundle/Entity/Contact.php namespace Acme\ContactBundle\Entity; use Mremi\ContactBundle\Entity\Contact as BaseContact; class Contact extends BaseContact { /** * @var int */ protected $id; }
<!-- src/Acme/ContactBundle/Resources/config/doctrine/Contact.orm.xml --> <?xml version="1.0" encoding="UTF-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Acme\ContactBundle\Entity\Contact" table="contact"> <id name="id" column="id" type="integer"> <generator strategy="AUTO" /> </id> </entity> </doctrine-mapping>
YML Version:
# src/Acme/ContactBundle/Resources/config/doctrine/Contact.orm.yml Acme\ContactBundle\Entity\Contact: type: entity table: contact id: id: type: integer generator: strategy: AUTO
Annotations Version:
<?php // src/Acme/ContactBundle/Entity/Contact.php namespace Acme\ContactBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Mremi\ContactBundle\Entity\Contact as BaseContact; /** * @ORM\Entity * @ORM\Table(name="contact") */ class Contact extends BaseContact { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; }
Step 4: Configure the MremiContactBundle
The bundle comes with a sensible default configuration, which is listed below. However you have to configure at least a recipient address.
# app/config/config.yml mremi_contact: store_data: false contact_class: Mremi\ContactBundle\Model\Contact form: type: mremi_contact name: contact_form validation_groups: [Default] subject_provider: mremi_contact.subject_provider.noop email: mailer: mremi_contact.mailer.twig_swift from: [] to: [] # Required template: MremiContactBundle:Contact:email.txt.twig
mremi_contact.email.from allows you to set the From address of the message:
# app/config/config.yml mremi_contact: email: from: - { address: john.doe@example.com, name: "John Doe" } - { address: foo.bar@example.com }
mremi_contact.email.to allows you to set the To address of the message:
# app/config/config.yml mremi_contact: email: to: - { address: webmaster@example.com, name: "Webmaster" } - { address: moderator@example.com }
You can also configure your favorite captcha. You have to install it by yourself and configure it here. You can get one from these bundles:
Or even implement your own.
# app/config/config.yml mremi_contact: form: captcha_type: genemu_captcha # or any other (genemu_recaptcha, ewz_recaptcha, ...)
Step 5: Import MremiContactBundle routing
Now that you have activated and configured the bundle, all that is left to do is import the MremiContactBundle routing file.
By importing the routing file you will have ready access the contact form.
In YAML:
# app/config/routing.yml mremi_contact_form: resource: "@MremiContactBundle/Resources/config/routing.xml"
Or if you prefer XML:
<!-- app/config/routing.xml --> <import resource="@MremiContactBundle/Resources/config/routing.xml"/>
Note:
In order to use the built-in email functionality, you must activate and configure the SwiftmailerBundle.
Step 6: Update your database schema (optional)
If you configured the data storage (step 3), you can now update your database schema.
If you want to first see the create table query:
$ app/console doctrine:schema:update --dump-sql
Then you can run it:
$ app/console doctrine:schema:update --force
You can now access to the contact form at http://example.com/app_dev.php/contact!
Note:
If your are in debug mode (see your front controller), the HTML5 validation can be disabled by adding
?novalidate=1to the URL.
Customization
Templating
If you want to customize some parts of this bundle (views for instance), read the Symfony documentation.
Events
The contact controller dispatches 3 events during the index action:
- ContactEvents::FORM_INITIALIZE occurs when the form is initialized
- ContactEvents::FORM_SUCCESS occurs when the form is submitted successfully
- ContactEvents::FORM_COMPLETED occurs after saving the contact in the contact form process
Each one allows you to customize the default workflow provided by this bundle.
Contribution
Any question or feedback? Open an issue and I will try to reply quickly.
A feature is missing here? Feel free to create a pull request to solve it!
I hope this has been useful and has helped you. If so, share it and recommend it! :)
mremi/contact-bundle 适用场景与选型建议
mremi/contact-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.57k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2013 年 07 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Symfony2」 「form」 「contact」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mremi/contact-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mremi/contact-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mremi/contact-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
A Laravel Filament Forms slug field.
Symfony2 Barcode Generator Bundle with Twig function extension
A jQuery augmented PHP library for creating and validating HTML forms
Symfony bundle to connect AWS sns and sqs to create offline queue processing
Integrate the doctrine-translatable extension in Symfony2
统计信息
- 总下载量: 12.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 9
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-07-02