1

I'm using a PHP (not CakePHP) vendor in my app.
I put vendor folder in "src/controller" and included it in "src/Controller/TelegramsController.php" set() method.

public function set() {
    require __DIR__ . '/vendor/autoload.php';
    $API_KEY = 'api key';
    $BOT_NAME = 'bot name';
    $hook_url = 'hook url';
    try {
        // Create Telegram API object
        $telegram = new Telegram($API_KEY, $BOT_NAME);

        // Set webhook
        $result = $telegram->setWebhook($hook_url);
        if ($result->isOk()) {
            echo $result->getDescription();
        }
    } catch (Longman\TelegramBot\Exception\TelegramException $e) {
        echo $e;
    }
}


When I call set() method, Telegram class displays response before CakePHP renders the view. And CakePHP displays this warning.
Unable to emit headers.
How can I manage Telegram class streaming out functions to display in CakePHP view (not before view)?

ndm
  • 59,784
  • 9
  • 71
  • 110
mitra razmara
  • 745
  • 6
  • 10

1 Answers1

0

That's not how you include composer-compatible libraries into a composer-compatible project, instead you composer require them and rely on the main autoloader included by the CakePHP application:

$ composer require longman/telegram-bot

Please read up on how composer works.

That being said, you are overwriting an existing controller method, the Controller::set() method is used to register data for use in view templates. Choose a different name for your controller action method, and use the existing set() method to pass data to your view template if required, alternatively return a properly prepared response object. In any case, do not echo data in controller actions!

See also

ndm
  • 59,784
  • 9
  • 71
  • 110
  • Thank you. [I tried "composer require longman/telegram-bot" but was not successful.](https://stackoverflow.com/questions/44106107/how-to-use-telegram-api-package-in-cakephp-3?) – mitra razmara May 25 '17 at 06:07
  • Sorry. I thought "telegram class" echoed the message. consider "telegram class" echoes some messages. Is there any way to wrap the messages if an external class (like telegram) echoes messages? – mitra razmara May 25 '17 at 06:08