Each controller has a series of 'actions' which are defined as class methods of the Controller classes. Each action has a specific responsibility, such as listing a set of objects, updating an object, or deleting an object. A controller object is instantiated by the Dispatcher (lithium\action\Dispatcher), and is given an instance of the lithium\action\Request class, which contains all necessary request state, including routing information, GET & POST data, and server variables. The controller is then invoked (using PHP's magic __invoke() syntax), and the proper action is called, according to the routing information stored in the Request object. A controller then returns a response (i.e. using redirect() or render()) which includes HTTP headers, and/or a serialized data response (JSON or XML, etc.) or HTML webpage. For more information on returning serialized data responses for web services, or manipulating template rendering from within your controllers, see the settings in $_render and the lithium\net\http\Media class.
See also: lithium\net\http\Media
See also: lithium\action\Dispatcher
See also: lithium\action\Controller::$_render
Inheritance: extends lithium\core\Object
 public function _init()
 {
     parent::_init();
     /*
     * 
     * if (!Session::read('user'))
      $this->redirect('Sessions::add');
     
     
      alliances::applyFilter('save', function($self, $params, $chain) {
     
      //Temporarily store our entity object so that we can manipulate it
      $record = $params['entity'];
     
      //If an id doesn't exist yet, then we know we're saving for the first time. If a
      //password is provided, we need to hash it
      var_dump($record->foto);
     
      //Write the modified object back to $params
      $params['entity'] = $record;
     
      //Allow the next filter to be run
      return $chain->next($self, $params, $chain);
      });
     * 
     * 
     */
 }
 protected function _init()
 {
     $this->_render['negotiate'] = true;
     parent::_init();
     self::$actief = array('start' => 'active', 'lijsten' => '', 'beheren' => '');
     self::$breadcrumb = array(array('naam' => 'Inloggen'));
 }
Exemplo n.º 3
0
 protected function _init()
 {
     parent::_init();
     $this->_config = (array) Libraries::get('li3_pecl_oauth');
     $this->_config += array('host' => $this->request->env('SERVER_NAME'), 'oauth_callback' => $this->request->env('SERVER_NAME') . '/oauth/client', 'namespace' => 'li3_pecl_oauth', 'redirect_success' => 'Client::index', 'redirect_failed' => array('Client::index', 'args' => array('failed' => true)));
     return Consumer::config($this->_config) ? true : false;
 }
Exemplo n.º 4
0
 public function _init()
 {
     parent::_init();
     if (!Session::read('user')) {
         $this->redirect('Sessions::add');
     }
 }
 protected function _init()
 {
     $this->_render['negotiate'] = true;
     parent::_init();
     $login = Auth::check('member');
     self::$actief = array('start' => '', 'overzicht' => '', 'lijsten' => 'active', 'beheren' => '');
     self::$breadcrumb = array(array('url' => '/permanentielijsten/lijsten', 'naam' => 'Lijsten'));
 }
Exemplo n.º 6
0
 protected function _init()
 {
     parent::_init();
     // 判断其是否从 mobile 端请求过来
     if (!empty($_SERVER['HTTP_USER_AGENT']) && HttpUserAgentUtil::is_mobile($_SERVER['HTTP_USER_AGENT'])) {
         $this->_mobile = true;
     }
 }
Exemplo n.º 7
0
 public function __construct($config = null)
 {
     $this->api = new ApontadorApi();
     $this->location = new Location();
     if (!empty($config)) {
         parent::__construct($config);
     }
 }
 public function _init()
 {
     $this->_render['negotiate'] = true;
     parent::_init();
     if (!Session::read('user')) {
         $this->redirect('Sessions::add');
     }
 }
Exemplo n.º 9
0
 protected function _init()
 {
     parent::_init();
     if ($this->_viewAs) {
         $this->_viewAs($this->_viewAs);
     } elseif (isset($this->request->params['backend']) && $this->request->params['backend']) {
         $this->_viewAs('backend-component');
     }
 }
 /**
  * Define application view paths
  */
 protected function _init()
 {
     $this->_render['renderer'] = 'File';
     $this->_render['paths']['template'] = '{:library}/views/{:controller}/';
     $this->_render['paths']['template'] .= '{:template}.{:type}.php';
     $this->_render['paths']['layout'] = '{:library}/views/layouts/default.{:type}.php';
     $this->_render['paths']['element'] = '{:library}/views/elements/{:template}.html.php';
     parent::_init();
 }
 protected function _init()
 {
     $this->_render['negotiate'] = true;
     parent::_init();
     $login = Auth::check('member');
     if (!$login) {
         return $this->redirect('/login');
     }
 }
Exemplo n.º 12
0
 public function __construct(array $config = array())
 {
     $this->api = new ApontadorApi();
     $apiConfig = new Config();
     $apiConfig->setBaseUrl(APONTADOR_URL);
     $apiConfig->setBasicAuth(new BasicAuth(APONTADOR_CONSUMER_KEY, APONTADOR_CONSUMER_SECRET));
     $apiConfig->setRestClient(new RestClient());
     $this->userRepository = new UserRepository($apiConfig);
     parent::__construct($config);
 }
Exemplo n.º 13
0
 protected function _init()
 {
     parent::_init();
     $isPostsExist = Model::connection()->read("SHOW TABLES LIKE 'posts'") ? true : false;
     $isUsersExist = Model::connection()->read("SHOW TABLES LIKE 'users'") ? true : false;
     if ($isPostsExist && $isUsersExist) {
         $users = Users::first();
         self::$_install = empty($users) ? false : true;
     }
 }
 protected function _init()
 {
     $this->_render['negotiate'] = true;
     parent::_init();
     $login = Auth::check('member');
     self::$actief = array('start' => '', 'lijsten' => '', 'beheren' => 'active');
     self::$breadcrumb = array(array('url' => 'beheren', 'naam' => 'Beheren'));
     if (!$login) {
         return $this->redirect('/login');
     }
 }
Exemplo n.º 15
0
 protected function _init()
 {
     parent::_init();
     # Check CSRF forgery signature
     if ($this->request->data and !RequestToken::check($this->request)) {
         throw new \Exception('Invalid request token.');
     }
     if (isset($this->request->data['security']['token'])) {
         unset($this->request->data['security']);
     }
     # Load active user
     $current_identity = Auth::check('any');
     if (is_object($current_identity)) {
         $u = $current_identity->getUser();
         $this->CURRENT_USER = $u;
     }
     $this->set(array('CURRENT_USER' => $this->CURRENT_USER));
 }
 /**
  * Override _init to set rendering type to json by default
  */
 public function _init()
 {
     $this->_render['type'] = 'json';
     parent::_init();
 }
Exemplo n.º 17
0
 protected function _init()
 {
     parent::_init();
     Consumer::config(array('service' => 'oauth2', 'scheme' => 'https', 'port' => '443', 'host' => 'graph.facebook.com', 'secondary_host' => 'www.facebook.com', 'client_id' => 'your_client_id', 'scope' => 'email,read_stream', 'client_secret' => 'your_client_secret', 'success' => 'http://localhost/facebook/success'));
 }
Exemplo n.º 18
0
 /**
  * Binds the messaging system to a controller to enable `'message'` option flags in various
  * controller methods, such as `render()` and `redirect()`.
  *
  * @param object $controller An instance of `lithium\action\Controller`.
  * @param array $options Options.
  * @return object Returns the passed `$controller` instance.
  */
 public static function bindTo(Controller $controller, array $options = array())
 {
     $controller->applyFilter('__invoke', function ($self, $params, $chain) {
         $data = array();
         $data['start'] = microtime(true);
         $data['memory'] = memory_get_usage(true);
         $data['name'] = Debugger::get('controller') . ':' . Debugger::get('action') . '->__invoke()';
         $result = $chain->next($self, $params, $chain);
         $data['end'] = microtime(true);
         $data['memory'] = memory_get_usage(true) - $data['memory'];
         $data['time'] = $data['end'] - $data['start'];
         Debugger::push('events', $data);
         Debugger::inc('events.time', $data['time']);
         return $result;
     });
     return $controller;
 }
Exemplo n.º 19
0
 /**
  * Setup controller to use application layout, and plugin view templates
  * Setup response headers for all actions
  */
 protected function _init()
 {
     $this->_render['paths'] = array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php', 'layout' => LITHIUM_APP_PATH . '/views/layouts/default.html.php', 'element' => LITHIUM_APP_PATH . '/views/elements/{:template}.html.php');
     parent::_init();
     $this->response->cache(false);
 }
Exemplo n.º 20
0
 protected function _init()
 {
     parent::_init();
     Consumer::config(array('host' => $this->request->env('SERVER_NAME'), 'oauth_consumer_key' => '59f87a2f8e430bbad5c84b61ed06304fc9204bcb', 'oauth_consumer_secret' => '4b498c24588bc56685e68f0d2c52ee6becf96ba3', 'request' => $this->request->env('base') . '/oauth/request_token', 'access' => $this->request->env('base') . '/oauth/access_token', 'authorize' => $this->request->env('base') . '/oauth/authorize', 'port' => 30501));
 }
Exemplo n.º 21
0
 protected function _init()
 {
     parent::_init();
     Provider::config(array('host' => $this->request->env('SERVER_NAME'), 'request' => $this->request->env('base') . '/oauth/request_token', 'access' => $this->request->env('base') . '/oauth/access_token', 'authorize' => $this->request->env('base') . '/oauth/authorize', 'port' => 30501));
 }
Exemplo n.º 22
0
 /**
  * _init()
  * 
  * Setup the php library
  */
 public function _init()
 {
     parent::_init();
     //var_dump(getBaseUrl());
     static::$_uploadHandler = new UploadHandler(array('script_url' => Router::match(array('Uploads::deleteAction', 'type' => 'json')), 'upload_dir' => LITHIUM_APP_PATH . '/webroot/upload/files/', 'upload_url' => '/upload/files/', 'param_name' => 'files', 'delete_type' => 'DELETE', 'max_file_size' => null, 'min_file_size' => 1, 'accept_file_types' => '/.+$/i', 'max_number_of_files' => null, 'max_width' => null, 'max_height' => null, 'min_width' => 1, 'min_height' => 1, 'discard_aborted_uploads' => true, 'orient_image' => false, 'image_versions' => array('thumbnail' => array('upload_dir' => LITHIUM_APP_PATH . '/webroot/upload/thumbnails/', 'upload_url' => '/upload/thumbnails/', 'max_width' => 80, 'max_height' => 80))));
 }
 public function _init()
 {
     parent::_init();
     $this->_render['paths'] = array('template' => array(LITHIUM_APP_PATH . '/views/{:controller}/{:template}.{:type}.php', LI3_ACTIVITIES_PATH . '/views/{:controller}/{:template}.{:type}.php', '{:library}/views/{:controller}/{:template}.{:type}.php'), 'layout' => array(LITHIUM_APP_PATH . '/views/layouts/{:layout}.{:type}.php', LI3_ACTIVITIES_PATH . '/views/layouts/{:layout}.{:type}.php', '{:library}/views/layouts/{:layout}.{:type}.php'), 'element' => array(LITHIUM_APP_PATH . '/views/elements/{:template}.{:type}.php', LI3_ACTIVITIES_PATH . '/views/elements/{:template}.{:type}.php', '{:library}/views/elements/{:template}.{:type}.php'), 'mustache' => array(LITHIUM_APP_PATH . '/views/mustache/{:template}.{:type}.php', LI3_ACTIVITIES_PATH . '/views/mustache/{:template}.{:type}.php', '{:library}/views/mustache/{:template}.{:type}.php'));
 }
Exemplo n.º 24
0
 protected function _init()
 {
     $this->_render['negotiate'] = true;
     parent::_init();
 }
Exemplo n.º 25
0
 public function __construct(array $config = array())
 {
     $this->api = new ApontadorApi();
     parent::__construct($config);
 }
Exemplo n.º 26
0
 protected function _init()
 {
     parent::_init();
     Consumer::config(array('host' => 'twitter.com', 'oauth_consumer_key' => '', 'oauth_consumer_secret' => ''));
 }
Exemplo n.º 27
0
 protected function _init()
 {
     parent::_init();
     $this->response->encoding = 'UTF-8';
 }
Exemplo n.º 28
0
 /**
  * automatic supplement of library for redirects
  *
  * @see lithium\net\http\Router::match()
  * @see lithium\action\Controller::$response
  * @see lithium\action\Controller::redirect()
  * @param mixed $url The location to redirect to, provided as a string relative to the root of
  *              the application, a fully-qualified URL, or an array of routing parameters to be
  *              resolved to a URL. Post-processed by `Router::match()`.
  * @param array $options Options when performing the redirect. Available options include:
  *              - `'status'` _integer_: The HTTP status code associated with the redirect.
  *                Defaults to `302`.
  *              - `'head'` _boolean_: Determines whether only headers are returned with the
  *                response. Defaults to `true`, in which case only headers and no body are
  *                returned. Set to `false` to render a body as well.
  *              - `'exit'` _boolean_: Exit immediately after rendering. Defaults to `false`.
  *                Because `redirect()` does not exit by default, you should always prefix calls
  *                with a `return` statement, so that the action is always immediately exited.
  * @return object Returns the instance of the `Response` object associated with this controller.
  */
 public function redirect($url, array $options = array())
 {
     return parent::redirect($this->_url($url), $options);
 }