Response of the Application
The response of the application must always be the result of the request made to it.
The response can be a string, by default it is an HTML string.
Here is an example of the response from a module or addon controller method:
public function index()
{
$data = array();
return $this->viewPHP($data, 'template');
}
The result returned by this method will be a string generated in the template.php
template.
Then this result will be received by the application object and sent to the user.
The response can also be an error message 404 (page not found):
public function index()
{
$id = $this->input->get('id', TYPE_UINT);
if ( ! $id) {
$this->errors->error404(); // the request will be aborted
}
return $this->viewPHP($data, 'template');
}
The response to an AJAX request can have the following format:
public function index()
{
$response = array('status'=>1);
$this->ajaxResponse($response);
}
{
"data": {
"status": 1
},
"errors": []
}
The response can also be a redirect to another page:
public function index()
{
if ( ! Users::id()) {
// The user is not authorized, redirect him to the login form page
$this->redirect(Users::url('login'));
}
}