public function execute(Request $request, Response $response) { try { $id = $request->get('id'); } catch (OutOfBoundsException $e) { throw new ControllerException('No bank account was specified.'); } try { $ba = $this->mapper->findById($id); } catch (OutOfBoundsException $e) { throw new ControllerException(sprintf('No bank account with id #%d exists.', $id)); } $response->set('id', $id); $response->set('balance', $ba->getBalance()); return 'BankAccountView'; }
public static function build($data, $allowCallbacks = true) { // Check it's being called with AJAX // But only if we tell it to if (!self::validOrigin()) { Error::log('Invalid origin'); exit; } // I do love a bit of json Response::set(200); // Store our encoded data as a variable $json = json_encode($data); // Just make sure if (!$json) { return; } // Do we allow ?callback=test parameters? if ($allowCallbacks === true) { $callback = preg_replace('/[^0-9a-z\\-_\\d]/i', '', Input::get('callback')); if ($callback) { $json = $callback . '(' . $json . ');'; } } // Give 'em what they wanted return $json; }
/** * Set response data * * @param string $key * @param $value * * @return $this * @see Response::set */ public function set($key, $value = null) { if (is_array($key)) { $this->response->sets($key); return $this; } $this->response->set($key, $value); return $this; }
public function loadView($what = '') { if (!isset(self::$vars['view'])) { if (file_exists(APP_BASE . 'views/' . $what . '.php')) { self::$vars['view'] = grab(APP_BASE . 'views/' . $what . '.php', self::$vars); } else { // Set a 404 Response::set(404); // If it doesn't exist, show the error view self::$vars['view'] = grab(APP_BASE . 'views/' . Config::get('404_page') . '.php', self::$vars); } } return self::$vars['view']; }
protected function postProcessResponse(Response $response, Controller $controllerInstance) { if (!$response instanceof Renderable || !$this->isInstalled()) { return false; } $response->set('user', $controllerInstance->getUser()->toArray()); $response->set('message', $controllerInstance->getMessage()); $response->set('errorMessage', $controllerInstance->getErrorMessage()); if ($controllerInstance instanceof FrontendController) { $response->set('currency', $controllerInstance->getRequestCurrency()); } // fetch queued EAV data if (class_exists('ActiveRecordModel', false)) { ActiveRecordModel::loadEav(); } $renderer = $this->getRenderer(); if ($response instanceof ActionResponse && !$controllerInstance->isBlocksProcessed) { $controllerInstance->isBlocksProcessed = true; foreach ($renderer->getBlockConfiguration() as $object => $commands) { foreach ($commands as $command) { if ($renderer->isBlock($object)) { $action = $command['action']; switch ($action['command']) { case 'replace': $action['command'] = 'append'; $controllerInstance->removeBlock($object); case 'append': case 'prepend': if (!empty($action['isDefinedBlock'])) { $action = array_merge($action, (array) array_shift($controllerInstance->getBlocks($action['view']))); } $controllerInstance->addBlock($object, $action['call'], $action['view'], $action['command'] == 'prepend'); break; case 'remove': $controllerInstance->removeBlock($object); break; case 'theme': $this->setTheme($action['view']); break; } } } } } }
private function assignAllTypes(Response $response) { $response->set('allTypes', array(DeliveryZone::BOTH_RATES => $this->translate('_tax_and_shipping_rates'), DeliveryZone::SHIPPING_RATES => $this->translate('_shipping_rates'), DeliveryZone::TAX_RATES => $this->translate('_tax_rates'))); }
public function execute(Request $request, Response $response) { $response->set('ids', $this->mapper->getAllIds()); return 'BankAccountListView'; }
public function listAllMovies() { $response = new Response(); $movies_db = $this->db->all(); $response->set(new Status(200), $movies_db); return $response; }