ibrows / newsletter-bundle
Symfony NewsletterBundle
4.0.2
2016-05-13 16:00 UTC
Requires
- stfalcon/tinymce-bundle: ^0.4
- symfony/symfony: >=2.8
README
一个不错的Symfony2 Newsletter Bundle
功能
- 不同的模板
- 处理不同的频道和组
- 电子邮件正文富文本编辑器
- 创建新闻通讯向导
- 处理正文块
- 电子邮件消息队列
- 统计信息
- 每个新闻通讯不同的用户
沙箱
查看我们的沙箱:https://github.com/ibrows/IbrowsNewsletterBundleSandbox 演示安装:http://newsletterbundle.ibrhost.com (用户:demo / 密码:demo)
如何安装
将Bundle添加到您的composer.json中
// composer.json { "require": { "ibrows/newsletter-bundle": "*" } }
使用composer.phar从控制台安装Bundle
$ php composer.phar update ibrows/newsletter-bundle
在AppKernel.php中启用Bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Stfalcon\Bundle\TinymceBundle\StfalconTinymceBundle(), new Ibrows\Bundle\NewsletterBundle\IbrowsNewsletterBundle(), ); }
配置
# app/config/ibrows_newsletter.yml ibrows_newsletter: mandants: # generate a secure token for each mandant! default: ThisTokenIsNotSoSecretChangeItdefault mandantA: ThisTokenIsNotSoSecretChangeItMandantA mandantB: ThisTokenIsNotSoSecretChangeItMandantB classes: # needed entities - see next step for creating them model: # most likely fos user user: Ibrows\YourBundle\Entity\User # depends on the namespace you set at mandant: Ibrows\YourBundle\Entity\Newsletter\Mandant newsletter: Ibrows\YourBundle\Entity\Newsletter\Newsletter subscriber: Ibrows\YourBundle\Entity\Newsletter\Subscriber design: Ibrows\YourBundle\Entity\Newsletter\Design block: Ibrows\YourBundle\Entity\Newsletter\Block group: Ibrows\YourBundle\Entity\Newsletter\Group readlog: Ibrows\YourBundle\Entity\Newsletter\Log\ReadLog sendlog: Ibrows\YourBundle\Entity\Newsletter\Log\SendLog sendsettings: Ibrows\YourBundle\Entity\Newsletter\SendSettings mailjob: Ibrows\YourBundle\Entity\Newsletter\MailJob filesystem: block: # where to store uploaded files (e.g. image uploads) directory: %kernel.root_dir%/../web/uploads/block # absolute path to the uploaded files public: /uploads/block # Host for public url generation of images host: http://example.com
# app/config/routing.yml # IbrowsNewsletter ibrows_newsletter: resource: "@IbrowsNewsletterBundle/Controller/" type: annotation prefix: /newsletter
# app/config/stfalcon_tinymce.yml stfalcon_tinymce: include_jquery: false tinymce_jquery: true selector: ".tinymce" # create own methods in your own RendererBridge and set here the icons and description for them tinymce_buttons: unsubscribelink: title: "Unsubscribe link" image: "http://placehold.it/30x30" now: title: "Current date" image: "http://placehold.it/30x30" gendertitle: title: "Gender title" image: "http://placehold.it/30x30" statisticlogreadimage: title: "Statistics image" image: "http://placehold.it/30x30" readonlinelink: title: "Read online link" image: "http://placehold.it/30x30" theme: simple: mode: "textareas" theme: "advanced" plugins: "fullscreen,table" theme_advanced_buttons2: "unsubscribelink,now,gendertitle,statisticlogreadimage,readonlinelink" #theme_advanced_buttons2: "tablecontrols"
# app/config/config.yml imports: # ... - { resource: stfalcon_tinymce.yml } - { resource: ibrows_newsletter.yml }
添加NoStreamBlob DBAL类型
# app/config/config.yml # Doctrine Configuration doctrine: dbal: types: nostreamblob: Ibrows\Bundle\NewsletterBundle\DBAL\Types\NoStreamBlobType
配置mandants
允许的mandants已在ibrows_newsletter.mandants中定义,位于ibrows_newsletter.yml下。可以独立于每个mandant运行数据库。为此,我们需要通知doctrine关于不同的连接
# app/config/config.yml # Doctrine Configuration doctrine: dbal: # ... connections: default: driver: %database_driver% host: %database_host% port: %database_port% dbname: %database_name% user: %database_user% password: %database_password% charset: UTF8 mandantA: driver: %database_driver_mandanta% host: %database_host_mandanta% port: %database_port_mandanta% dbname: %database_name_mandanta% user: %database_user_mandanta% password: %database_password_mandanta% charset: UTF8 mandantB: driver: %database_driver_mandantb% host: %database_host_mandantb% port: %database_port_mandantb% dbname: %database_name_mandantb% user: %database_user_mandantb% password: %database_password_mandantb% orm: # ... entity_managers: default: connection: default mappings: YourBundle: ~ # FOSUserBundle: ~ # ... mandantA: connection: mandantA mappings: ibrows_newsletter: type: annotation prefix: YourBundle\Entity\Newsletter dir: "%kernel.root_dir%/../src/Ibrows/YourBundle/Entity/Newsletter" is_bundle: false mandantB: connection: mandantB mappings: ibrows_newsletter: type: annotation prefix: YourBundle\Entity\Newsletter dir: "%kernel.root_dir%/../src/Ibrows/YourBundle/Entity/Newsletter" is_bundle: false
连接设置
# app/config/parameters.yml parameters: database_driver: pdo_mysql database_host: 127.0.0.1 database_port: ~ database_name: newslettersandbox database_user: user database_password: pass database_driver_mandanta: pdo_mysql database_host_mandanta: 127.0.0.1 database_port_mandanta: ~ database_name_mandanta: newslettersandbox_mandanta database_user_mandanta: user database_password_mandanta: pass database_driver_mandantb: pdo_mysql database_host_mandantb: 127.0.0.1 database_port_mandantb: ~ database_name_mandantb: newslettersandbox_mandantb database_user_mandantb: user database_password_mandantb: pass
启用配置的mandants
# create the databases $ php app/console doctrine:schema:create --em default $ php app/console doctrine:schema:create --em mandantA $ php app/console doctrine:schema:create --em mandantB # enable the mandants (insert them in the defined database - already existings will be ignored) $ php app/console ibrows:newsletter:mandants:enable
生成所需的实体
$ php app/console ibrows:newsletter:entities:generate Ibrows\\YourBundle\\Entity
改进您的用户类 - 实现MandantUserInterface
这个概念背后的想法是一个用户实体,通过symfony安全组件进行身份验证(最有可能始终存储在默认连接 - 数据库中)。现在这个实体需要实现MandantUserInterface,以便让IbrowsNewsletterBundle知道应该使用哪个mandant。
# YourBundle\Entity\User (e.g. FOSUser implementation) <?php namespace YourBundle\Entity; use FOS\UserBundle\Entity\User as BaseUser; use Doctrine\ORM\Mapping as ORM; use Ibrows\Bundle\NewsletterBundle\Model\User\MandantUserInterface; /** * @ORM\Entity * @ORM\Table(name="fos_user") */ class User extends BaseUser implements MandantUserInterface { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="string", nullable=true) */ protected $mandant; /** * @return string */ public function getMandant() { return $this->mandant; } }
将默认连接中的用户(例如FOSUser)与mandant关联
UPDATE `fos_user` SET mandant = "default" WHERE username = "YourUsername"; UPDATE `fos_user` SET mandant = "mandantA" WHERE username = "YourUsernameA"; UPDATE `fos_user` SET mandant = "mandantB" WHERE username = "YourUsernameB";
开始
- 在浏览器中打开您的项目
- 使用具有有效mandant的用户进行身份验证
- 打开/newsletter (app_dev.php/newsletter)
- 创建设计
- 创建新闻通讯
- 祝您玩得开心
自定义
- 实现自己的GenderTitleStrategy以设置正确的问候语
- 实现自己的RendererBridge以提供更多方法
路线图
- 实现前端内联编辑