black-lamp/yii2-email-templates 问题修复 & 功能扩展

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

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

black-lamp/yii2-email-templates

Composer 安装命令:

composer require black-lamp/yii2-email-templates

包简介

Module for adding templates for email letters across dashboard

README 文档

README

Module for adding templates for email letters across dashboard

Build Status Latest Stable Version Latest Unstable Version License

Installation

Run command

composer require black-lamp/yii2-email-templates

or add

"black-lamp/yii2-email-templates": "^3.0.0"

to the require section of your composer.json.

Applying migrations

yii migrate --migrationPath=@vendor/black-lamp/yii2-email-templates/src/migrations

Add module to application config

Backend module for create, edit and delete email templates

'modules' => [
     // ...
     'email-templates' => [
         'class' => bl\emailTemplates\EmailTemplates::class,
         'languageProvider' => [
            'class' => bl\emailTemplates\providers\DbLanguageProvider::class,
            'tableName' => 'language',
            'idField' => 'id',
            'nameField' => 'name'
         ]
     ],
]

languageProvider it's a class that implements LanguageProviderInterface. You can use language providers from this extension or create yours. This extension has two language providers.

Database language provider configuration properties
Option Description Type Default
tableName Name of table in database with languages string language
idField Name of field in language table with primary key string id
idName Name of field in language table with language name string name
Config language provider configuration properties
Option Description Type Default
languages Array with languages. Example [1 => 'English', 2 => 'Russian'] array -
defaultLanguage Array with default language. Array must contains one value. Example [1 => 'English'] array -

Add component to application config

Component for getting the templates from database

'components' => [
    // ...
    'emailTemplates' => [
        'class' => bl\emailTemplates\components\TemplateManager::class
    ],
]

Using

  1. Create the template with markers across dashboard

Email subject

New message from {sitename}

Email body

Hello, {username}!

Text...

Go to the link - {link}

  1. Get template by key with component help
$template = Yii::$app->templateManager->getTemplate('test', 1);

This method return a Template object.

  1. You should to parse the markers in email subject and email body
    $template->parseSubject([
        '{sitename}' => $sitename
    ]);
    
    $template->parseBody([
        '{username}' => Yii::$app->user->identity->firstname,
        '{link}' => Url::toRoute(['/confirm', 'token' => $token], true)
    ]);
  1. Now you can using this template
Yii::$app->mailer->compose()
    // ...
    ->setSubject($template->subject)
    ->setHtmlBody($template->body)
    // ...

统计信息

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

GitHub 信息

  • Stars: 10
  • Watchers: 4
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-11-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固