php - PHP fatal error : Call to undefined method K2P_API_OCWRITER::cleanPost(). OpenCart

标签 php error-handling opencart

我收到此错误:

PHP Fatal error: Call to undefined method K2P_API_OCWRITER::cleanPost() in /home/key2demo/domains/key2datafeed.com/public_html/ocdemoshops/oc23/key2publish/k2p_api_OCwriter.php on line 142



这行代码是:
$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;
        }
    }
}

?>

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

谢谢!

最佳答案

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

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

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

关于php - PHP fatal error : Call to undefined method K2P_API_OCWRITER::cleanPost(). OpenCart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43497107/

相关文章:

php - MySQLi bind_param() 不工作

c# - 无效的对象名称(即使存在)

php - set_error_handler回调函数中的$ errno是什么?

javascript - 将 JS 和 CSS 代码添加到 Opencart header

php - 如何使多个产品在opencart中显示为单个产品

php - 将 PHP 函数转换为 JavaScript

PHP 页面加载似乎在请求自身并误解了结果

php - 通过路由参数过滤和学说查询获取并显示正确的数据

java - 构建DOM文档对象时文件过早结束错误

xml - OpenCart - 即时创建 sitemap.xml(每次)或将其保存到磁盘并缓存?