dongli1887 2015-10-23 02:54
浏览 78

在joomla中制作Web服务的最佳方法是什么?

Hi guys today I have a interesting question.

What's the best way to make a webservices in joomla? I'm trying to make a web services in joomla and I have following problem:

in the controller of the view: components/com_webservice/view/view.json.php

<?php 

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class WebServicesViewServices extends JViewLegacy {

    private $data;

function __construct($config = array()) {
        JLoader::import('models.services', JPATH_COMPONENT);
        $model = new WebServicesModelServices();

        if ($model->errors) {
            echo json_encode($model->errors);
            jexit();
        }else{
            $this->data = array('iphone' => '5s','iphone' => '6','iphone' => '6s','iphone' => '6s plus');
        }
        parent::__construct($config);
    }

    function display($tpl = null) {
      echo json_encode($this->data);
    }
}
?>

The problem is, if I execute: curl http://wsn.jserver/index.php?option=com_services&format=json to consume this services, this response me

* Connected to wsn.jserver (127.0.0.1) port 80 (#0)
> GET /index.php?option=com_jserver HTTP/1.1
> Host: wsn.jserver
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 303 See other
< Date: Fri, 23 Oct 2015 02:40:37 GMT
< Server: Apache/2.4.16 (Unix) PHP/5.5.30
< X-Powered-By: PHP/5.5.30
< Set-Cookie: 4dbb8abeb5e7919ee73c8545901d5f62=d6ksd6e93t99q7hsk8cf10hq35; path=/; HttpOnly
< Set-Cookie: e909c2d7067ea37437cf97fe11d91bd0=DO
< Location: http://wsn.jserver/index.php?lang=es
< Content-Length: 0
< Content-Type: text/html; charset=utf-8
<
* Connection #0 to host wsn.jserver left intact

How can I do that this work? what is the best way to make webservices in joomla?

  • 写回答

2条回答 默认 最新

  • donglengli0644 2015-10-23 07:43
    关注

    Have you checked the JoomlaTools Framework? From the linked page:

    Designed around the HTTP protocol. Each component automatically provides a level 3 JSON REST API out of the box, no extra coding required.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化