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".