如何从xmlrpc服务器codeigniter传递参数到控制器方法

时间:2013-09-11 08:26:08

标签: codeigniter xmlhttprequest xml-rpc

我在将参数值从xmlrpc服务器传递给控制器​​方法时出现问题,该控制器方法是使用cron作业递归调用的。  我的xml rpc服务器方法:

function update_p($request) {
        $parameters = $request->output_parameters();

        $_GET["portfolio"] = $parameters['0']["portfolio"];
        $_GET["filter"] = $parameters['0']["filter"];
        $_GET["sort"] = $parameters['0']["sort"];
        $_GET["first"] = $parameters['0']["first"];
        $_GET["watch"] = $parameters['0']["watch"];
        redirect("controllerClass/update_p");

        return 1;
    }

我的控制器类,我想传递所有这些参数组合,过滤器等方法:

  

public function update_p(){           $ loginid = $ this-> session-> userdata('loginid');           如果(!isset($登录ID)){               死;           }

    error_reporting(E_ERROR);
    if (time()>$this->session->userdata('expire'))
     

{redirect(“/ dashboard / logout?expired = Y”,“location”,401);死; }

    $out='';

    $request="USER ".$loginid.($this->session->userdata('isMobile')?"@mobile":"")."\n";

    if(isset($_GET["portfolio"])) {
        $portfolio=trim($_GET["portfolio"]);
        $request.='ECHO "LISTP":'."\nLISTP0 #".$portfolio;
        if(isset($_GET["filter"])) {
            $filter=trim($_GET["filter"]);
            $request.=" -".$filter;
        }
        if(isset($_GET["sort"])) {
            $sort=trim($_GET["sort"]);
            if ($sort>=1024) $request.=" -s".($sort&1023);
            else $request.=" -S".$sort;
        }
        $ph = isset($_GET["first"]);
        if ($ph) { 
            $this->load->model('modelmethod');
            $resultArray = $this->modelmethod->getData($this->session->userdata('loginid'),$this->session->userdata('isMobile')?'mobile':'default','listp');
            $request.=" ".$resultArray[0]['listp'];
        }
        $request.="\nECHO ,\n";
        if(isset($_GET["watch"])) {
            $portfolio=trim($_GET["watch"]);
            if ($ph)
                $resultArray = $this->modelmethod->getData($this->session->userdata('loginid'),$this->session->userdata('isMobile')?'mobile':'default','watch');
            $request.='ECHO "watchl":'."\nLISTP1 #".$portfolio." -WL ".($ph?$resultArray[0]['watch']:"")."\n";
            $request.='ECHO ,"watchs":'."\nLISTP1 #".$portfolio." -WS\nECHO ,\n";
        }
    }
    $request.="RISk\nECHO ,\nPnL\n";

    if ($result=$this->getData($request."BYE\n")) {
        if (result!='') $out=$result."\n";
    }

    ob_start('ob_gzhandler');
    echo "{".$out."}";
    ob_end_flush();

}

我正在尝试使用此代码使用firbug控制台测试它:

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://example/api/v1/update_p?");
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("portfolio=0&filter=A&sort=1&first=Y");

任何帮助都将非常感谢谢谢。

1 个答案:

答案 0 :(得分:0)

希望有所帮助:
编辑1:

function update_p($request) {
    $parameters = $request->output_parameters();

    $_GET["portfolio"] = $parameters['0']["portfolio"];
    $_GET["filter"] = $parameters['0']["filter"];
    $_GET["sort"] = $parameters['0']["sort"];
    $_GET["first"] = $parameters['0']["first"];
    $_GET["watch"] = $parameters['0']["watch"];
    //redirect("controllerClass/update_p/".$_GET["portfolio"].'/'.$_GET["filter"].'/'.$_GET["sort"].'/'.$_GET["first"].'/'.$_GET["watch"], 'refresh');
    $url   = base_url("controllerClass/update_p/".$_GET["portfolio"].'/'.$_GET["filter"].'/'.$_GET["sort"].'/'.$_GET["first"].'/'.$_GET["watch"]);
    header("Location: $url");

    return 1;
}

控制器方法

function update_p(){
    $portfolio  = $this->uri->segment(3);
    $filter     = $this->uri->segment(4);
    $sort       = $this->uri->segment(5);
    $first      = $this->uri->segment(6);
    $watch      = $this->uri->segment(7);
}