$this->response->body = json_encode($data);but I get warning: controller should return a string or a Response object, support for the $controller->response object is deprecated.
echo json_encode($data);or is there something else I should use?
class Controller_Ajax extends Controller_Rest {
public $params;
public $response;
private $user_id;
private $token;
private $data;
private $success;
private $message;
private $output;
public function before($data = null) {
parent::before();
if (!Sentry::check()) {
die('not logged in');
}
$this->user_id = Session::get('user_id');
$this->params = json_decode(stripslashes(Input::post('params')));
$this->token = Input::post('csrf_token');
$this->success = false;
$this->message = null;
$this->output = null;
$this->code = 200;
}
public function router($resource, array $arguments) {
$pattern = '/\.(' . implode('|', array_keys($this->_supported_formats)) . ')$/';
// Check if a file extension is used
if (preg_match($pattern, $resource, $matches)) {
// Remove the extension from arguments too
$resource = preg_replace($pattern, '', $resource);
$this->format = $matches[1];
} else {
// Which format should the data be returned in?
$this->format = $this->_detect_format();
}
if (Security::check_token($this->token) == false) {
$this->message = 'page has expired, please refresh and try again';
return;
}
// If they call user, go to $this->post_user();
$controller_method = strtolower(\Input::method()) . '_' . $resource;
// If method is not available, set status code to 404
if (method_exists($this, $controller_method)) {
if (call_user_func_array(array($this, $controller_method), $arguments) == true) {
$this->success = true;
}
} else {
$this->message = "unknown method $controller_method";
$this->response->status = 404;
return;
}
}
public function after($response) {
$this->response(array('success' => $this->success, 'message' => $this->message, 'output' => $this->output), $this->code);
return parent::after($response);
}
It looks like you're new here. If you want to get involved, click one of these buttons!