当前位置: 首页>>代码示例>>PHP>>正文


PHP Controller::before方法代码示例

本文整理汇总了PHP中Controller::before方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::before方法的具体用法?PHP Controller::before怎么用?PHP Controller::before使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Controller的用法示例。


在下文中一共展示了Controller::before方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: before

 public function before()
 {
     parent::before();
     if (!Group::current('allow_finance') || !Group::current('show_all_jobs')) {
         throw new HTTP_Exception_403('Forbidden');
     }
 }
开发者ID:nikulinsanya,项目名称:exeltek,代码行数:7,代码来源:Payment.php

示例2: before

	function before()
	{
		parent::before();

		\Config::load('rest', true);

		if (\Config::get('rest.auth') == 'basic')
		{
			$this->_prepare_basic_auth();
		}

		elseif (\Config::get('rest.auth') == 'digest')
		{
			$this->_prepare_digest_auth();
		}

		// Some Methods cant have a body
		$this->request->body = NULL;

		// Which format should the data be returned in?
		$this->request->format = $this->_detect_format();

		// Which format should the data be returned in?
		$this->request->lang = $this->_detect_lang();
	}
开发者ID:ralf57,项目名称:fuel,代码行数:25,代码来源:rest.php

示例3: before

 public function before()
 {
     parent::before();
     $this->params = Arr::extract($this->request->param(), array('year', 'month', 'day'));
     View::bind_global('params', $this->params);
     View::bind_global('content', $this->content);
 }
开发者ID:noikiy,项目名称:kohana,代码行数:7,代码来源:Log.php

示例4: before

 /**
  * Construct controller
  */
 public function before()
 {
     // Log request
     Jelly::factory('api_request')->set(array('ip' => Request::$client_ip, 'request' => $this->request->uri . (empty($_GET) ? '' : '?' . http_build_query($_GET))))->save();
     // Rate limit
     $rate_span = Kohana::config('api.rate_span');
     $rate_limit = Kohana::config('api.rate_limit');
     $requests = Model_API_Request::request_count(time() - $rate_span, Request::$client_ip);
     $requests_left = $rate_limit - $requests;
     if ($requests_left < 0) {
         throw new Controller_API_Exception('Request limit reached');
     }
     // Check version
     $this->version = $this->request->param('version');
     if (!in_array($this->version, self::$_versions)) {
         throw new Controller_API_Exception('Invalid version');
     }
     // Check format
     $this->format = $this->request->param('format');
     !$this->format and $this->format = self::FORMAT_JSON;
     if (!in_array($this->format, self::$_formats)) {
         throw new Controller_API_Exception('Invalid format');
     }
     // Set result defaults
     $this->data = array('version' => $this->version, 'requests' => $requests, 'requests_left' => $requests_left, 'request_window' => $rate_span);
     return parent::before();
 }
开发者ID:netbiel,项目名称:core,代码行数:30,代码来源:api.php

示例5: before

 public function before()
 {
     parent::before();
     header("Last-Modified: " . gmdate('D, d M Y H:i:s T', time()));
     header("Expires: " . gmdate('D, d M Y H:i:s T', time() + 315360000));
     header("Cache-Control: max-age=315360000");
 }
开发者ID:andygoo,项目名称:kohana,代码行数:7,代码来源:Media.php

示例6: before

 /**
  * @throws HTTP_Exception_401
  * @since 1.0
  */
 public function before()
 {
     parent::before();
     // Check request signature
     if (Kohana::$config->load('hapi.require_signature') && !HAPI_Security::is_request_signature_valid($this->request)) {
         HAPI_Security::require_auth('Request signature was invalid');
     }
     // Login using basic auth
     if (array_key_exists('authorization', $this->request->headers())) {
         HAPI_Security::login($this->request->headers('authorization'));
     }
     // Check that user is authenticated
     if ($this->_require_login && !HAPI_Security::is_request_authenticated($this->request)) {
         HAPI_Security::require_auth();
     }
     // Instantiate the encoder object for the response (based on the Accept header)
     $this->response_encoder = $this->_get_response_encoder();
     // Set current language
     $supported_languages = Kohana::$config->load('hapi.supported_languages');
     $preferred_language = $this->request->headers()->preferred_language($supported_languages);
     if ($preferred_language) {
         I18n::lang($preferred_language);
     }
     $extract_array = function ($keys) {
         if (empty($keys)) {
             return [];
         }
         return explode(',', $keys);
     };
     // Filter response keys
     $this->_paths = $extract_array($this->request->query('paths'));
 }
开发者ID:anroots,项目名称:kohana-hapi,代码行数:36,代码来源:HAPI.php

示例7: before

 /**
  * The before() method is called before controller action
  *
  * @uses  Request::param
  * @uses  Theme::set_theme
  */
 public function before()
 {
     if ($theme = $this->request->param('theme', FALSE)) {
         Theme::set_theme($theme);
     }
     parent::before();
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:13,代码来源:media.php

示例8: before

 public function before()
 {
     parent::before();
     // Borrowed from userguide
     if (isset($_GET['lang'])) {
         $lang = $_GET['lang'];
         // Make sure the translations is valid
         $translations = Kohana::message('langify', 'translations');
         if (in_array($lang, array_keys($translations))) {
             // Set the language cookie
             Cookie::set('langify_language', $lang, Date::YEAR);
         }
         // Reload the page
         $this->request->redirect($this->request->uri());
     }
     // Set the translation language
     I18n::$lang = Cookie::get('langify_language', Kohana::config('langify')->lang);
     // Borrowed from Vendo
     // Automaticly load a view class based on action.
     $view_name = $this->view_prefix . Request::current()->action();
     if (Kohana::find_file('classes', strtolower(str_replace('_', '/', $view_name)))) {
         $this->view = new $view_name();
         $this->view->set('version', $this->version);
     }
 }
开发者ID:Hinton,项目名称:langify,代码行数:25,代码来源:base.php

示例9: before

 public function before()
 {
     parent::before();
     $this->detect_language();
     /* Вспомогательный класс */
     $this->api = new Api();
     $this->auth_token = $this->request->headers('tokenAuth');
     /* Обрабатываем POST со строкой json */
     $this->post = json_decode($HTTP_RAW_POST_DATA = file_get_contents('php://input'), true);
     /* Инициализация параметров limit и offset для запроса, по умолчанию limit = 10, offset = 0 */
     $this->offset = Security::xss_clean(Arr::get($this->post, 'offset', 0));
     $this->limit = Security::xss_clean(Arr::get($this->post, 'limit', 10));
     //Инициализация типа для запроса и id Для запроса
     $option = Security::xss_clean(Arr::get($this->post, 'option', array()));
     $this->entryType = strtolower(Security::xss_clean(Arr::get($option, 'entryType', '')));
     $this->entryId = Security::xss_clean(Arr::get($option, 'entryId', ''));
     /* строка поиска */
     $this->searchText = Security::xss_clean(Arr::get($option, 'searchText', ''));
     /* текст коммента */
     $this->text = Security::xss_clean(Arr::get($this->post, 'text', ''));
     $this->id = (int) $this->request->param('id', 0);
     /* обновление времени жизни токена     если он существует и если его ещё надо обновлять (живой ли?) */
     if (!empty($this->auth_token)) {
         if ($this->api->token_expires($this->auth_token)) {
             $token_auth = Security::xss_clean(Arr::get($this->post, 'tokenAuth', ''));
             $this->api->update_token($token_auth);
         }
     }
 }
开发者ID:HappyKennyD,项目名称:teest,代码行数:29,代码来源:Core.php

示例10: before

 /**
  * Construct controller.
  *
  * @throws  Controller_API_Exception  on invalid version, rate limit exceeded, invalid format
  */
 public function before()
 {
     // Log request
     $api_request = Model_API_Request::factory();
     $api_request->ip = Request::$client_ip;
     $api_request->request = $this->request->uri() . (empty($_REQUEST) ? '' : '?' . http_build_query($_REQUEST));
     $api_request->created = time();
     $api_request->save();
     // Check version
     $this->version = $this->request->param('version');
     if (!in_array($this->version, self::$_versions)) {
         throw new Controller_API_Exception('Invalid version');
     }
     $this->data['version'] = $this->version;
     // Rate limit
     $rate_limit = (int) Kohana::$config->load('api.rate_limit');
     $rate_span = (int) Kohana::$config->load('api.rate_span');
     if ($rate_limit) {
         $requests = Model_API_Request::request_count(time() - $rate_span, Request::$client_ip);
         $requests_left = $rate_limit - $requests;
         if ($requests_left < 0) {
             throw new Controller_API_Exception('Request limit reached');
         }
         $this->data['requests'] = $requests;
         $this->data['requests_left'] = $requests_left;
         $this->data['request_window'] = $rate_span;
     }
     // Check format
     $this->format = $this->request->param('format');
     !$this->format and $this->format = self::FORMAT_JSON;
     if (!in_array($this->format, self::$_formats)) {
         throw new Controller_API_Exception('Invalid format');
     }
     parent::before();
 }
开发者ID:anqh,项目名称:core,代码行数:40,代码来源:api.php

示例11: before

 public function before()
 {
     if (Kohana::find_file('views', $this->main_template)) {
         $this->main_template = View::factory($this->main_template);
         $system_settings = ORM::factory('Systemsetting')->where('name', 'IN', array('language', 'title', 'keywords', 'description', 'copyright'))->find_all()->as_array('name', 'value');
         $language_parts = explode('-', $system_settings['language']);
         $this->main_template->head_style = '';
         $this->main_template->html_lang = $language_parts[0];
         /* Print language as ISO: from "en-us" only "en", described at: http://www.w3schools.com/Tags/ref_language_codes.asp */
         $this->main_template->title = $system_settings['title'];
         $this->main_template->meta_keywords = $system_settings['keywords'];
         $this->main_template->meta_description = $system_settings['description'];
         $this->main_template->meta_copyright = $system_settings['copyright'];
         $this->main_template->content = '';
     }
     $dir = strtolower($this->request->directory()) . "/" . str_replace('_', '/', strtolower($this->request->controller()));
     $file = $this->request->action();
     if (Kohana::find_file('views/' . $dir, $file)) {
         $this->template = View::factory($dir . '/' . $file);
         $this->template->data = array();
         $this->template->data["errors"] = array();
         $this->template->data["values"] = array();
     }
     parent::before();
 }
开发者ID:Workhaven,项目名称:workhaven,代码行数:25,代码来源:Template.php

示例12: before

 public function before()
 {
     if ($this->request->method() == HTTP_Request::OPTIONS) {
         $this->request->action('options');
     }
     parent::before();
 }
开发者ID:nolanglee,项目名称:platform,代码行数:7,代码来源:OAuth.php

示例13: before

 public function before()
 {
     parent::before();
     if (!Group::current('is_admin')) {
         throw new HTTP_Exception_403('Forbidden');
     }
 }
开发者ID:nikulinsanya,项目名称:exeltek,代码行数:7,代码来源:Structure.php

示例14: before

 public function before()
 {
     parent::before();
     // Save the old action so it can be brought back on after
     $this->_action = $this->request->action;
     // Set the current action
     $current_action = $this->request->action;
     $id = $this->request->param('id', NULL);
     // Let's guess the action based on the params
     if (!in_array($this->request->action, array('edit', 'add', 'delete')) and (!is_null($id) or !empty($id))) {
         $current_action = 'read';
     }
     if (!method_exists($this, 'action_' . $this->request->action)) {
         $model = Jelly::select(Inflector::singular($this->request->controller));
         foreach ($model->get_state() as $key => $value) {
             $param = $this->request->param($key, NULL);
             if (!is_null($param)) {
                 $model->set_state($key, $param);
             }
         }
         $this->request->response = Kostache::factory($this->request->controller . '/' . $current_action)->set_model($model);
         // Since the magic has been executed, just execute an empty action
         $this->request->action = 'default';
     }
 }
开发者ID:raeldc,项目名称:kojo-plugin,代码行数:25,代码来源:controller.php

示例15: before

 public function before()
 {
     parent::before();
     if (!Group::current('allow_assign')) {
         throw new HTTP_Exception_403();
     }
 }
开发者ID:nikulinsanya,项目名称:exeltek,代码行数:7,代码来源:Attachments.php


注:本文中的Controller::before方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。