致命错误:在Cron.php中调用未定义的函数doGet()

时间:2014-08-22 09:45:05

标签: php xml api soap cron

我正在尝试使用外部webservices API发出XML请求,但我一直收到以下错误:

Fatal error: Call to undefined function doGet()

问题在于这一行:

    $xml = new SimpleXMLElement(doGet (getBaseUrl ("GetAllChassis_WithYears") . "&manufacturerID=$manufacturerId"));

但我不明白为什么没有定义???

这是我的剧本

<?php

    class Namespace_Module_Model_Cron
    {

        public function setHeaders ()
        {

            header ("Expires: Mon, 26 Jul 2020 05:00:00 GMT");
            header ("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");
            header ("Cache-Control: no-store, no-cache, must-revalidate");
            header ("Cache-Control: post-check=0, pre-check=0", false);
            header ("Pragma: no-cache");
            session_start ();
            $vehicle = $_SESSION["vehicle"];
            if (!isset($vehicle)) {
                $vehicle = array();
                $_SESSION["vehicle"] = $vehicle;
            }

        }

        public function appendSessionId ()
        {

            return ini_get ("use_trans_sid" !== true) ? htmlspecialchars (SID) : "";

        }

        public function doGet ($url)
        {
            $ch = curl_init ($url);
            curl_setopt ($ch, CURLOPT_FAILONERROR, 1);
            curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt ($ch, CURLOPT_TIMEOUT, 15);
            $response = curl_exec ($ch);
            curl_close ($ch);
            return $response;
        }

        public function checkXmlErrors ($xml)
        {
            if ($xml === false) {
                echo "<p>Failed loading XML</p>";
                foreach (libxml_get_errors () as $error) {
                    echo "<p>" . $error->message . "</p>";
                }

                return false;
            }

            return true;
        }

        public function getBaseUrl ($method)
        {
            $username = "username";
            $password = "password";
            $baseUrl = "http://api.wheelwizards.net/eu/webservice.asmx/";
            return $baseUrl . $method . "?username=$username&password=$password";
        }

        public function getAllChassis ($manufacturerId)
        {
            $xml = new SimpleXMLElement(doGet (getBaseUrl ("GetAllChassis_WithYears") . "&manufacturerID=$manufacturerId"));
            if (checkXmlErrors ($xml)) {
                $chassis = array();
                foreach ($xml->AllChassisReturn as $AllChassisReturn) {
                    $chass = array();
                    $chass["id"] = (string)$AllChassisReturn->ChassisID;
                    $chass["title"] = (string)$AllChassisReturn->ChassisTitle . " " . (string)$AllChassisReturn->UKYear;
                    $chassis[] = $chass;
                }

                // Sort by title
                $titles = array();
                foreach ($chassis as $key => $value) {
                    $titles[$key] = $value["title"];
                }
                array_multisort ($titles, SORT_ASC, SORT_STRING, $chassis);
                Mage::log ($xml, Zend_Log::INFO, 'layout.log', true);
                return $chassis;
            } else {
                return false;
            }
        }

        public function getAllManufacturers ()
        {
            $xml = new SimpleXMLElement(doGet (getBaseUrl ("GetAllManufacturers_WithYears")));
            if (checkXmlErrors ($xml)) {
                $manufacturers = array();
                foreach ($xml->AllManufacturersReturn as $AllManufacturersReturn) {
                    $manufacturer = array();
                    $manufacturer["id"] = (string)$AllManufacturersReturn->ManufacturerID;
                    $manufacturer["name"] = (string)$AllManufacturersReturn->ManufacturerName;

                    $manufacturers[] = $manufacturer;
                }

                // Sort by name
                $names = array();
                foreach ($manufacturers as $key => $value) {
                    $names[$key] = $value["name"];
                }
                array_multisort ($names, SORT_ASC, SORT_STRING, $manufacturers);
                Mage::log ($xml, Zend_Log::INFO, 'layout.log', true);
                return $manufacturers;
            } else {
                return false;
            }
        }

        public function getAllModels ($chassisId)
        {
            $xml = new SimpleXMLElement(doGet (getBaseUrl ("GetAllModels_WithYears") . "&chassisID=$chassisId"));
            if (checkXmlErrors ($xml)) {
                $models = array();
                foreach ($xml->AllModelsReturn as $AllModelsReturn) {
                    $model = array();
                    $model["id"] = (string)$AllModelsReturn->ModelID;
                    $model["name"] = (string)$AllModelsReturn->ModelName;
                    $models[] = $model;
                }

                // Sort by name
                $names = array();
                foreach ($models as $key => $value) {
                    $names[$key] = $value["name"];
                }
                array_multisort ($names, SORT_ASC, SORT_STRING, $models);
                Mage::log ($xml, Zend_Log::INFO, 'layout.log', true);
                return $models;
            } else {
                return false;
            }
        }
}

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

doGet()应为$this->doGet()

相关问题