archer/clickatell-bundle

Symfony ClickatellBundle

此软件包的规范存储库似乎已不存在,因此该软件包已被冻结。

安装次数: 49,631

依赖者: 0

建议者: 0

安全: 0

星标: 2

关注者: 1

分支: 2

公开问题: 1

类型:symfony-bundle

0.1.0 2016-08-17 12:37 UTC

This package is auto-updated.

Last update: 2020-03-28 08:54:42 UTC


README

Clickatell

先决条件

本版本的分包需要 Symfony 2.1+。

翻译

如果您希望使用此分包中提供的默认文本,请确保您已在其配置中启用了翻译器。

# app/config/config.yml

framework:
    translator: ~

有关翻译的更多信息,请参阅Symfony 文档

安装

安装是一个简单的5步骤过程。

  1. 使用 composer 下载 ArcherClickatellBundle。
  2. 启用 Bundle。
  3. 创建您的消息类。
  4. 配置 ArcherClickatellBundle。
  5. 更新您的数据库模式。

第1步:使用 composer 下载 ArcherClickatellBundle

在您的 composer.json 中添加 ArcherClickatellBundle。

{
    "require": {
        "archer/clickatell-bundle": "dev-master"
    }
}

现在,运行以下命令让 composer 下载分包。

$ php composer.phar update archer/clickatell-bundle

Composer 将分包安装到您的项目的 vendor/archer 目录。

第2步:启用分包

在内核中启用分包。

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Archer\ClickatellBundle\ArcherClickatellBundle(),
    );
}

第3步:创建您的消息类

此分包的目标是将一些 Message 类持久化到数据库中(MySQL、MongoDB、CouchDB 等)。

该分包提供了基类,这些基类已经为大多数字段进行了映射,以便于创建实体。以下是使用方法:

  1. 扩展基 Message 类(要使用的类取决于您的存储)
  2. 映射 id 字段。它必须被保护,因为它是从父类继承的。

注意

文档使用了一个名为 AcmeMessageBundle 的分包。如果您想使用相同的名称,您需要在内核中注册它。但您当然可以将您的消息类放在您想要的分包中。

警告

如果您在您的消息类中覆盖了 __construct() 方法,请确保调用 parent::__construct(),因为基消息类依赖于它来初始化一些字段。

a) Doctrine ORM 消息类

如果您通过 Doctrine ORM 持久化消息,则您的 message 类应位于您的分包的 Entity 命名空间中,并像这样开始:

<?php
// src/Acme/MessageBundle/Entity/Message.php

namespace Acme\MessageBundle\Entity;

use Archer\ClickatellBundle\Entity\Message as BaseMessage;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="clickatell_message")
 */
class Message extends BaseMessage
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}

b) MongoDB 消息类 c) CouchDB 消息类 d) Propel 消息类

第4步:配置 ArcherClickatell

根据您使用的数据存储类型,将以下配置添加到您的 config.yml 文件中。

# app/config/config.yml
archer_clickatell:
    user:                 ~ # your username for clickatell
    password:             ~ # your password for clickatell
    api_id:               ~ # your id for clickatell
    message_class:  Acme\MessageBundle\Entity\Message
# app/config/config.xml
<!-- app/config/config.xml -->

<archer_clickatell:config
    user="username"
    password="password"
    api-id="api_id"
    message-class="Acme\MessageBundle\Entity\Message"
/>

第5步:更新您的数据库模式

现在配置好bundle后,你需要做的是更新你的数据库模式,因为你在第4步中添加了一个新实体,即你创建的Message类。

对于ORM,请运行以下命令。

$ php app/console doctrine:schema:update --force

使用步骤

//send  Sms
$form = $this->get('clickatell.send_message.form');
$form->bind($this->getRequest());
if ($form->isValid()) {
    $message = $form->getData();
    $clickatell = $this->get('clickatell.http');
    $response = $clickatell->sendMessage($message->getToPhone(), $message->getText());
}