douhuang1973 2013-08-01 19:25
浏览 68

Joomla 2.5网站任务不会开火

Here is my issue. I have a form that I want to send data to a JSON task. However no matter what I do the task will not run. I just get the following error:

Invalid controller: name='controls', format='json'

As far as I can see there is nothing that should prevent the controller from running. Here is the code.

class HelloWorldControllerControls extends JController{
    /*function __construct(){
        parent::__construct();
    }*/
    public function postal(){
        JFactory::getDocument()->setMimeEncoding( 'application/json' );
        JResponse::setHeader('Content-Disposition','attachment;filename="status.json"');
        //$postal = JRequest::getVar('postal_code',false);
        //$dispatcher = JDispatcher::getInstance();
        //$saveLocalCookie = $dispatcher->trigger('onSavePostalCode', array('code'=>$postal));
        echo json_encode(array('success'=>true));
        jexit();
    }
}

This is of course in the site controllers folder and named controls.json.php

I have matched this with another controller I am using in the admin panel that does pretty much the exact same thing, but it works in admin, not in the site.

The JRoute I am using to try to call this is.

index.php?option=com_helloworld&task=controls.postal&format=json

Anything I may be overlooking?

EDIT:

To clarify, I need to call the task directly, as all I will be doing is outputting raw data in JSON format, there is no need for a view, only a model an controller. Currently since I am still in testing there is no need for the model yet.

EDIT 2:

Found part of an answer, but am going to leave it open as this answer is not really that great. Its impossible based on how Joomla sets up MVC in the "site" portion (based on my tests). It always looks for view first, then controller. I could only get the task to fire by making sure a view was set. There is a chance I am wrong and misled from my tests because an open source framework not building MVC correctly seems illogical.

So in order to fix this you need to use a "view" as a "controller".

  • 写回答

2条回答 默认 最新

  • doushi3454 2013-08-01 20:12
    关注

    The controller file name should be controls.php

    OR

    maybe if the output is raw, name it controls.raw.php and add &format=raw at the end.

    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决