簡體   English   中英

opencart 類別 api 返回 {“category”:null} 錯誤

[英]opencart category api return {“category”:null} error

我創建了 api 從 opencart 獲取類別列表以用於 android 應用程序。 已經有許多類別列表可用,但是當我嘗試點擊 api 時收到錯誤消息“{“category”:null}”

目錄->控制器->api

以下是代碼:

<?php

class ControllerApicategory extends Controller
{
public function index() 
{
        
        $this->load->model('catalog/category');
        $this->load->model('tool/image');

        $json = array();
        $json['category'] = array();
        $filter_data = array();
         
         $results = $this->model_catalog_category->getCategory($filter_data);
        # -- $_GET params ------------------------------
        
        if (isset($this->request->get['id'])) {
            $category_id = $this->request->get['id'];
        } else {
            $category_id = 0;
        }

        # -- End $_GET params --------------------------

        
        
        $json['category'] = array(
            'id'                    => $category['category_id'],
            'name'                  => $category['name'],
            'description'           => $category['description'],
            'href'                  => $this->url->link('product/category', 'category_id=' . $result['category_id'])
        );

        $json['category'] = $data['category'];
        $this->response->addHeader('Content-Type: application/json');
        $this->response->setOutput(json_encode($json));
        }
    }

請解決這個問題。

有兩個錯誤

  1. getCategory function 接受 integer 參數

$json['category']= $data['category'];

公共 function 索引(){

    $this->load->model('catalog/category');
    $this->load->model('tool/image');

    $json = array();
    $json['category'] = array();
 
    
    if (isset($this->request->get['id'])) {
        $category_id = $this->request->get['id'];
    } else {
        $category_id = 0;
    }

     $category = $this->model_catalog_category->getCategory($category_id);
    
    $json['category'] = array(
        'id'                    => $category['category_id'],
        'name'                  => $category['name'],
        'description'           => $category['description'],
        'href'                  => $this->url->link('product/category', 'category_id=' . $category['category_id'])
   );
    $this->response->addHeader('Content-Type: application/json');
    $this->response->setOutput(json_encode($json));
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM