title: PHP Fatal error: Call to undefined method K2P_API_OCWRITER::cleanPost(). OpenCart
body: <p>I get this error:</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>It is this line of code:</p>
  
  <pre><code>$command = $myAPI-&gt;cleanPost($_POST['command']);
  </code></pre>
  
  <p>This is all the code:</p>
  
  <pre><code>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-&gt;set('load', $loader);
  
  $config = new Config();
  $config-&gt;load('default');
  
  $config-&gt;load($application_config);
  $registry-&gt;set('config', $config);
  $registry-&gt;set('request', new Request());
  $response = new Response();
  
  $response-&gt;addHeader('Content-Type: text/html; charset=utf-8');
  $registry-&gt;set('response', $response);
  
  $registry-&gt;set('cache', new Cache($config-&gt;get('cache_type'), $config-&gt;get('cache_expire')));
  $registry-&gt;set('url', new Url($config-&gt;get('site_ssl')));
  
  $language = new Language($config-&gt;get('language_default'));
  $language-&gt;load($config-&gt;get('language_default'));
  
  $registry-&gt;set('language', $language);
  $registry-&gt;set('document', new Document());
  
  $event = new Event($registry);
  $registry-&gt;set('event', $event);
  
  if ($config-&gt;get('db_autostart')) {
      $registry-&gt;set('db', new DB($config-&gt;get('db_type'), $config-&gt;get('db_hostname'), $config-&gt;get('db_username'), $config-&gt;get('db_password'), $config-&gt;get('db_database'), $config-&gt;get('db_port')));
  }
  
  if ($config-&gt;get('session_autostart')) {
      $session = new Session();
      $session-&gt;start();
      $registry-&gt;set('session', $session);
  }
  
  if ($config-&gt;has('action_event')) {
      foreach ($config-&gt;get('action_event') as $key =&gt; $value) {
          $event-&gt;register($key, new Action($value));
      }
  }
  
  if ($config-&gt;has('config_autoload')) {
      foreach ($config-&gt;get('config_autoload') as $value) {
          $loader-&gt;config($value);
      }
  }
  
  if ($config-&gt;has('language_autoload')) {
      foreach ($config-&gt;get('language_autoload') as $value) {
          $loader-&gt;language($value);
      }
  }
  
  if ($config-&gt;has('library_autoload')) {
      foreach ($config-&gt;get('library_autoload') as $value) {
          $loader-&gt;library($value);
      }
  }
  
  if ($config-&gt;has('model_autoload')) {
      foreach ($config-&gt;get('model_autoload') as $value) {
          $loader-&gt;model($value);
      }
  }
  
  class K2P_API_OCWRITER extends Controller
  {
      private $errors;
      private $admin;
      private $adminValidated;
      private $adminShops;
  
      public function __construct($registry)
      {
          parent::__construct($registry);
          $this-&gt;errors = array();
      }
  
      public function doLog($message)
      {
          file_put_contents('./key2_log.txt', $message, FILE_APPEND);
      }
  
      public function login($usr, $pwd)
      {   
  
          if ($this-&gt;user-&gt;login($usr, $pwd)) {
              return true;
              $this-&gt;doLog('logged in');
          } else {
              $this-&gt;doLog('Failed to login, please supply a valid username/password and check your webshop url');
              die;
          }
  
      }
  
      public function getLanguages()
      {
         $this-&gt;load-&gt;modal('localisation/language');
          $languages = $this-&gt;{'model_localisation_language'}-&gt;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-&gt;set('db', $db);
  $registry-&gt;set('user', new Cart\User($registry));
  $registry-&gt;set('tax', new Cart\Tax($registry));
  
  $myAPI = new K2P_API_OCWRITER($registry);
  $myAPI-&gt;config-&gt;set("config_language_id",LANGUAGE);
  $command = $myAPI-&gt;cleanPost($_POST['command']);
  $steps = $myAPI-&gt;cleanPost($_POST['steps']);
  $page = $myAPI-&gt;cleanPost($_POST['page']);
  $usr = $myAPI-&gt;cleanPost($_POST['usr']);
  $pwd = $myAPI-&gt;cleanPost($_POST['pwd']);
  //$myAPI-&gt;doLog(PHP_EOL . 'pages: ' . $page);
  //$myAPI-&gt;doLog(PHP_EOL . 'steps: ' . $steps);
  $totalProducts = $myAPI-&gt;getProductCount();
  if ($myAPI-&gt;checkInput($usr,$pwd,$command,$page,$steps)) {
      if ($myAPI-&gt;login($usr, $pwd)) {
          switch($command){
              case "getCategoryCount":
                  echo json_encode($myAPI-&gt;getCategoryCount(),JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES);
                  break;
              case "getProductCount";
                  echo json_encode($myAPI-&gt;getProductCount(),JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES);
                  break;
              case "getCategories":
                  echo json_encode($myAPI-&gt;getCategories($steps, $page, JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES));
                  break;
              case "getProducts":
                  echo json_encode($myAPI-&gt;getProducts($steps, $page, JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES));
                  break;
              default:
                  echo "Invalid command!";
                  break;
          }
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>Does anyone know what is going wrong and how to fix it?</p>
  
  <p>Thanks!</p>