PHPAGI使用CakePHP SHELL

时间:2012-03-07 17:53:30

标签: cakephp asterisk

我最近需要为使用cakePHP构建的应用程序构建基于星号的IVR。

我想使用cake(胖)模型,所以我不必重写业务逻辑。

我想创建一个可以从星号拨号方案调用的cakePHP shell。

这就是我的所作所为。

将phpagi下载到vendors / phpagi。

修改了phpagi.php
function AGI($config=NULL, $optconfig=array())

为:

function AGI($config=NULL, $optconfig=array(), $stdin, $stdout)

所以我可以设置stdin和stdout。在第167行附近我改变了

  $this->in = defined('STDIN') ? STDIN : fopen('php://stdin', 'r');
  $this->out = defined('STDOUT') ? STDOUT : fopen('php://stdout', 'w');

  $this->in = $stdin;
  $this->out = $stdout;

在我vendors/shells的shell中,我添加了

 App::import('Vendor', 'AGI', array('phpagi/phpagi.php'));

我还添加了

    var $agi;
    //redirect output through agi conlog
    function err($message,$newlines = 1){
            $this->agi->conlog($message);
    }
    function out($message, $newlines =1){
            $this->agi->conlog($message);
    }
    //disable default message
    function startup(){

    }

,应用程序代码在

    function main(){
            $this->agi = new AGI(NULL, array(), $this->Dispatch->stdin,$this->Dispatch->stdout);
            $this->agi->answer();
            //do stuff here
    }

并在拨号方案中运行此操作,您需要做的就是

exten => s,n,AGI(${full/path/to/cake.php},${shellname},-app,${var/www/html/{appname}/app},-console,var/www/html/{appname}/cake/console/)

确保修复蛋糕目录的权限。

我想知道是否还有其他方法可以做到这一点?

1 个答案:

答案 0 :(得分:2)

Here is a class将为你完成所有工作。它由FreePBX维护 - 最受欢迎的Asterisk GUI,并在FreePBX中广泛使用。