PHP致命错误:调用未定义的方法K2P_API_OCWRITER :: cleanPost()。 Opencart的

时间:2017-04-19 13:25:39

标签: php error-handling opencart

我收到此错误:

  

PHP致命错误:在第142行的/home/key2demo/domains/key2datafeed.com/public_html/ocdemoshops/oc23/key2publish/k2p_api_OCwriter.php中调用未定义的方法K2P_API_OCWRITER :: cleanPost()

正是这行代码:

$command = $myAPI->cleanPost($_POST['command']);

这是所有代码:

define("VERSION", "1.0");
define("LANGUAGE", "1");

if (is_file('./../admin/config.php')) {
    require_once('./../admin/config.php');
}

require_once(DIR_SYSTEM . 'startup.php');

$application_config = 'admin';
$registry = new Registry();

$loader = new Loader($registry);
$registry->set('load', $loader);

$config = new Config();
$config->load('default');

$config->load($application_config);
$registry->set('config', $config);
$registry->set('request', new Request());
$response = new Response();

$response->addHeader('Content-Type: text/html; charset=utf-8');
$registry->set('response', $response);

$registry->set('cache', new Cache($config->get('cache_type'), $config->get('cache_expire')));
$registry->set('url', new Url($config->get('site_ssl')));

$language = new Language($config->get('language_default'));
$language->load($config->get('language_default'));

$registry->set('language', $language);
$registry->set('document', new Document());

$event = new Event($registry);
$registry->set('event', $event);

if ($config->get('db_autostart')) {
    $registry->set('db', new DB($config->get('db_type'), $config->get('db_hostname'), $config->get('db_username'), $config->get('db_password'), $config->get('db_database'), $config->get('db_port')));
}

if ($config->get('session_autostart')) {
    $session = new Session();
    $session->start();
    $registry->set('session', $session);
}

if ($config->has('action_event')) {
    foreach ($config->get('action_event') as $key => $value) {
        $event->register($key, new Action($value));
    }
}

if ($config->has('config_autoload')) {
    foreach ($config->get('config_autoload') as $value) {
        $loader->config($value);
    }
}

if ($config->has('language_autoload')) {
    foreach ($config->get('language_autoload') as $value) {
        $loader->language($value);
    }
}

if ($config->has('library_autoload')) {
    foreach ($config->get('library_autoload') as $value) {
        $loader->library($value);
    }
}

if ($config->has('model_autoload')) {
    foreach ($config->get('model_autoload') as $value) {
        $loader->model($value);
    }
}

class K2P_API_OCWRITER extends Controller
{
    private $errors;
    private $admin;
    private $adminValidated;
    private $adminShops;

    public function __construct($registry)
    {
        parent::__construct($registry);
        $this->errors = array();
    }

    public function doLog($message)
    {
        file_put_contents('./key2_log.txt', $message, FILE_APPEND);
    }

    public function login($usr, $pwd)
    {   

        if ($this->user->login($usr, $pwd)) {
            return true;
            $this->doLog('logged in');
        } else {
            $this->doLog('Failed to login, please supply a valid username/password and check your webshop url');
            die;
        }

    }

    public function getLanguages()
    {
       $this->load->modal('localisation/language');
        $languages = $this->{'model_localisation_language'}->getLanguages();
        doLog($languages, true);

        $langs = "";
        foreach ($languages as $language) {
            $lang = array();
            $lang["lang_id"] =  $language['language_id'];
            $lang["name"] =  $language['name'];
            $langs[] = $lang;
        }

        return $langs;
    }

}

$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);
$registry->set('user', new Cart\User($registry));
$registry->set('tax', new Cart\Tax($registry));

$myAPI = new K2P_API_OCWRITER($registry);
$myAPI->config->set("config_language_id",LANGUAGE);
$command = $myAPI->cleanPost($_POST['command']);
$steps = $myAPI->cleanPost($_POST['steps']);
$page = $myAPI->cleanPost($_POST['page']);
$usr = $myAPI->cleanPost($_POST['usr']);
$pwd = $myAPI->cleanPost($_POST['pwd']);
//$myAPI->doLog(PHP_EOL . 'pages: ' . $page);
//$myAPI->doLog(PHP_EOL . 'steps: ' . $steps);
$totalProducts = $myAPI->getProductCount();
if ($myAPI->checkInput($usr,$pwd,$command,$page,$steps)) {
    if ($myAPI->login($usr, $pwd)) {
        switch($command){
            case "getCategoryCount":
                echo json_encode($myAPI->getCategoryCount(),JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES);
                break;
            case "getProductCount";
                echo json_encode($myAPI->getProductCount(),JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES);
                break;
            case "getCategories":
                echo json_encode($myAPI->getCategories($steps, $page, JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES));
                break;
            case "getProducts":
                echo json_encode($myAPI->getProducts($steps, $page, JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES));
                break;
            default:
                echo "Invalid command!";
                break;
        }
    }
}

?>

有谁知道出了什么问题以及如何解决它?

谢谢!

1 个答案:

答案 0 :(得分:0)

错误不在该行代码中,而是在下一行中:

$command = $myAPI->cleanPost($_POST['command']);

您正在K2P_API_OCWRITER类中调用方法cleanPost,但该方法不存在。错误代码行已移位,但这是您在一个文件中堆积所有代码所能获得的。