1

I am trying to send sms using cakephp-sms plugin

The documentation is quite clear and brief. I installed it using Composer in my app/Plugin directory. I also installed xi-sms using composer. This was installed in the Vendor directory. In my controller for sending sms. I included App::uses('CakeSms', 'Sms.Network/Sms') and implemented an InfobipSmsTransport class in the Sms/Lib/Network/Sms. Below is my class

<?php

   use Xi\Sms\Gateway\InfobipGateway;

   App::uses('AbstractSmsTransport', 'Sms.Network/Sms');
   class InfobipSmsTransport extends AbstractSmsTransport {
   const INFOBIP_USER = 'XXXXX';
   const INFOBIP_PASSWORD = 'XXXXXXX';

   /**

    *
    * @param CakeSms $sms
   * @return bool Success
   */
  public function send(CakeSms $sms) {
    $gw = new InfobipGateway(
        self::INFOBIP_USER,
        self::INFOBIP_PASSWORD
    );

    $service = new Xi\Sms\SmsService($gw);

    $msg = new Xi\Sms\SmsMessage(
        $sms->message(),
        $sms->from(),
        $sms->to()
    );

    $response = $service->send($msg);

    return !empty($response);
   }
 }
?>

When I try to send an SMS however I get the following error Class "InfobipSmsTransport" not found.. I have no idea what am doing wrong? Any clues or suggestions are welcome.

msmolcic
  • 6,407
  • 8
  • 32
  • 56
Wasswa Samuel
  • 2,139
  • 3
  • 30
  • 54
  • `class in the Sms/Lib/Network/Sms` - that's supposed to be a folder, not a file. Assuming that's not the error the best course of action is to debug where the class isn't being found. Uou may find it useful to debug [the App::load](https://github.com/cakephp/cakephp/blob/2.7/lib/Cake/Core/App.php#L563-L569) function - e.g. print the file varaible from this line `if (file_exists($file)) {` and compare the paths being checked for your class to where you've put it - You'll probably find they are different. – AD7six Sep 09 '15 at 09:49

1 Answers1

0

The CakeSms class was not loading the plugin. This is the line of code where it was failing. App::uses($transportClassname, $plugin . 'Network/Sms');.

In my app/Config/sms.php I just changed this 'transport' =>'Infobip' to
'transport' =>'Sms.Infobip'. The plugin is now being loaded properly and the class is found.

Wasswa Samuel
  • 2,139
  • 3
  • 30
  • 54