定制 luyadev/luya-module-mailchimp 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

luyadev/luya-module-mailchimp

Composer 安装命令:

composer require luyadev/luya-module-mailchimp

包简介

This module provides a simple way to build your own form for a user registration in a MailChimp newsletter.

README 文档

README

LUYA Logo

LUYA MAILCHIMP MODULE

LUYA Total Downloads Latest Stable Version Join the chat at https://gitter.im/luyadev/luya

This module provides a simple way to build your own form for a user registration in a MailChimp newsletter.

Preparation

Before you install and configure the module you've to setup you Mailchimp account. After a successful registration, create a new mailing list and add you list fields. It's recommended to add them directly under Settings > List fields and |MERGE| tags in your list view. After you've setup your mailing list, extract the list id and note all your list field names. Additionally you'll need to get your API key for your account. With this informations you're ready to setup the mailchimp luya module.

Installation

Require the mailchimp module via composer

composer require luyadev/luya-module-mailchimp

add the mailchimp form module to your config:

'modules' => [
    //...
    'newsletter-form' => [
        'class' => 'luya\mailchimp\Module',
        'listId' => 'MailChimp-List-ID',
        'attributes' => [
            'email', 'firstname', 'lastname', 'street', 'zip_city', 'country'
        ],
        'rules' => [
            [['email', 'firstname', 'lastname', 'zip_city', 'country'], 'required'],
            ['email', 'email'],
        ],
        'attributeLabels' => [
            'email' => 'E-Mail',
            'firstname' => 'Firstname',
            'lastname' => 'Lastname',
            'street' => 'Street',
            'zip_city' => 'Zip/City',
            'country' => 'Country',
        ],
        'recipients' => [
            'registration-confirm@host.ip',
        ],
        'mailchimpApi' => 'MailChimp API Key',
    ],

By default LUYA will wrap the value into the Yii::t('app', $value) functions so you are able to translate the attributes labels. In the above example 'E-Mail' or 'Firstname' would look like this Yii::t('app', 'E-Mail') and Yii::t('app', 'Firstname').

Enter your API key in mailchimpAPI, your list id in listid and all list fields in attributes, rules and attributeLabels. As you can see your list field names in mailchimp will be used as model attributes which then can be validated via Yii rules defined in rules.

View Files

Create two view files in your module name directory in your views folder: _mail.php and index.php

_mail.php

Define your email confirmation admin mail in this view. If you've left recipient empty, no confirmation mail will be sent and you can skip the view definition.

<h2><?= Yii::$app->siteTitle;?> Newsletter Registration</h2>
<table border="0" cellpadding="5" cellspacing="2" width="100%">
<?php foreach($model->getAttributes() as $key => $value): ?>
    <tr>
        <td><b><?= $model->getAttributeLabel($key); ?>:</b></td>
        <td><?= nl2br($value); ?></td>
    </tr>
<?php endforeach; ?>
</table>

index.php

Define your registration form in this view. It includes the success and error message output as well. The form fields have to be correspond to attributes definition:

<?php

use yii\widgets\ActiveForm;
use yii\helpers\Html;

<?php if (Yii::$app->session->getFlash('mailchimpSuccess')): ?>
    <div class="alert alert-success">You've successfully subscribed to the newsletter.</div>
<?php else: ?>
    <?php $form = ActiveForm::begin(); ?>
        <?= $form->field($model, 'email'); ?>
        <?= $form->field($model, 'firstname'); ?>
        <?= $form->field($model, 'lastname'); ?>
        <?= $form->field($model, 'zip_city'); ?>
        <?= $form->field($model, 'country'); ?>
        <?= Html::submitButton(Yii::t('app', 'Submit'), ['class' => 'btn btn-primary']) ?>
    <?php ActiveForm::end(); ?>
<?php endif; ?>

Send current language

To let Mailchimp know what language the visitor is using, add the field mc_language to attributes and create a safe rule for it (or add it to the require rule).

In the view file, add the following line:

<?= $form->field($model, 'mc_language')->hiddenInput(['value'=> Yii::$app->composition->langShortCode])->label(false) ?>

Embed the Module in the CMS

Add a new module page and choose your configured mailchimp-module-name. In the config example above we used newsletter-form. Make sure the site is visible and online and you're ready to use the module to register users via your defined custom forms to your mailchimp newsletter list.

Something isn't working as expected

You can check the API calls to your account in mailchimp account with the given responds on the same page where you get your API key. Just scroll to the bottom.

luyadev/luya-module-mailchimp 适用场景与选型建议

luyadev/luya-module-mailchimp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.89k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「mailchimp」 「newsletter」 「form」 「module」 「cms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 luyadev/luya-module-mailchimp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 luyadev/luya-module-mailchimp 我们能提供哪些服务?
定制开发 / 二次开发

基于 luyadev/luya-module-mailchimp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-21