chronon / ymlp
一个 CakePHP 2.x 插件组件,用于与 YMLP/Your Mailing List Provider 的 API 进行交互。
Requires
- php: >=5.3.0
- ext-curl: *
- composer/installers: *
This package is not auto-updated.
Last update: 2024-09-11 12:30:57 UTC
README
注意:此项目已过时,很可能不会再更新。它仍然是 CakePHP 2.x 应用程序的 YMLP API 解决方案,但不会为 CakePHP 3.x 更新。
YMLP,或您的邮件列表提供商,是一个提供免费和付费账户的电子邮件通讯录和营销服务,API 编写得很好。
该组件将 CakePHP 应用程序与 YMLP 的 API 进行交互。
您需要在 YMLP 上拥有一个免费或付费账户,以及您的用户名和 API 密钥(可在 ymlp.com 的“配置”,“API”下找到)。请确保在 YMLP 的 API 页面上启用 API 访问!
兼容性
已与 CakePHP 2.8.x 进行测试。需要 PHP 5 且支持 cURL。
安装
在您的项目 composer.json
文件中
{
"require": {
"chronon/ymlp": "*"
}
}
使用 git
git clone git@github.com:chronon/CakePHP-YmlpComponent-Plugin.git APP/Plugin/Ymlp
配置
所有配置都在 APP/Config/bootstrap.php 中。
必需:加载插件
CakePlugin::load('Ymlp');
或
CakePlugin::loadAll();
必需:设置您的 YMLP API 密钥和用户名。
Configure::write('Ymlp.settings', array( 'Key' => '1234567890ABCDEFG', 'Username' => 'yourusername', ));
必需:设置您的 YMLP 字段映射,即您的本地字段 => YMLPField。
Configure::write('Ymlp.fieldMap', array( 'email' => 'Email', ));
用法
将组件添加到您的控制器中
public $components = array('Ymlp.Ymlp');
示例:如果您有一个名为 email
的订阅者表单字段,$this->request->data
将类似于以下内容
['Subscriber'] => array( 'email' => 'some@email.com' )
要使用该组件将此电子邮件地址添加到 YMLP
$result = $this->Ymlp->command('Contacts.Add', $this->request->data['Subscriber']);
$result
将是 YMLP 的 Contacts.Add()
方法返回的响应。请参阅 YMLP 文档了解所有可用的 API 命令。
此组件的可用方法
utility($method, $data = array()) /** * A utility method to send anything to the YMLP API * * @param string $method The YMLP API method call * @param array $data Data to pass to the YMLP method * @return string * @access public */ command($method, $data) /** * The primary method to format data, post it to the YMLP API, and then format * the returned result. * * @param string $method The YMLP API method call * @param array $data Data to pass to the YMLP method * @return string * @access public */
使用 utility
方法的示例用法以查看配置的 YMLP 字段列表。如果您在 YMLP 中创建了一个收集姓名、电子邮件地址和邮寄地址的表单,您需要将应用程序的字段与 YMLP 字段相匹配。YMLP API 的 Fields.GetList()
方法可以为您提供所需的信息。
在控制器中创建一个临时方法并使用组件的 utility
方法
public function utility() { $result = $this->Ymlp->utility('Fields.GetList'); debug($result); exit; }
访问 /utility,您应该会看到一个 YMLP 配置的字段列表,包括字段 ID,您可以使用它将配置数组中的 Ymlp.fieldMap
与应用程序的字段进行映射。
Configure::write('Ymlp.fieldMap', array( 'email' => 'Email', 'first_name' => 1, 'last_name' => 2, 'address' => 3, 'city' => 4, 'state' => 5, 'zip' => 6, ));