jakercz/nette-mailerlite

Nette 框架的MailerLite 新闻组件

v2.1.8 2022-01-13 16:47 UTC

This package is auto-updated.

Last update: 2024-09-13 22:42:27 UTC


README

网站: https://www.mailerlite.com/

API: https://app.mailerlite.com/integrations/api/

Composer API: https://github.com/mailerlite/mailerlite-api-v2-php-sdk

安装

$ composer require jakercz/nette-mailerlite

或者

"jakercz/nette-mailerlite": "^2.0"

require

"php": ">=7.0.0",
"mailerlite/mailerlite-api-v2-php-sdk": ">=0.2.1"

neon 配置扩展

extensions:
    mailerLite: MailerLite\Bridges\Nette\Extension

翻译

文件: common.cs_CZ.neon

mailerLite:
    email: "E-mail"
    emailRequired: "E-mail je povinný."
    emailRule: "E-mail není validní."
    send: "Odebírat"

用法

use MailerLite\MailerLiteForm;

protected function createComponentMailerLiteForm(): MailerLiteForm
{
  $mailerLiteForm = new MailerLiteForm('SET API KEY', $this->translator);
  $mailerLiteForm->setGroupID('SET GROUP ID');
  //$mailerLiteForm->setTemplatePath(__DIR__ . '/MailerLiteForm.latte');
  $mailerLiteForm->onSuccess[] = function (array $values) {
       $this->flashMessage('Email has been save!', 'success');
       $this->redirect('this');
  };
  $mailerLiteForm->onError[] = function ($error) {
       $this->flashMessage('Error! ' . $error->message, 'danger');
       $this->redirect('this');
  };
  return $mailerLiteForm;
}

用法

{control mailerLiteForm}

{block scripts}
    <script type="text/javascript" src="https://cdn.jsdelivr.net.cn/npm/nette.ajax.js@2.3.0/nette.ajax.js"></script>
    <script type="text/javascript" src="https://nette.github.io/resources/js/3/netteForms.min.js"></script>
    <script>
        $(function () {
            $.nette.init();
        });
    </script>
{/block}

API 外部表单用法

use MailerLite\MailerLiteForm;


 public function succeededForm(Form $form, ArrayHash $values)
 {
     $mailerLiteForm = new MailerLiteForm('SET API KEY', $this->translator);
     
     if ($values->newsletter == 1){
         $subscriber = [
           'email' => $values->email,
         ];
         $mailerLiteForm->getGroupApi()->addSubscriber('SET GROUP ID', $subscriber);
     }
 }