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


PHP Session::read方法代码示例

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


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

示例1: redirectUrl

 /**
  * {@inheritDoc}
  */
 public function redirectUrl($url = null)
 {
     if ($url === null) {
         return $this->_session->read($this->_config['redirect']);
     }
     if ($url === false) {
         $this->_session->delete($this->_config['redirect']);
         return null;
     }
     $this->_session->write($this->_config['redirect'], $url);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:14,代码来源:SessionStorage.php

示例2: assertSession

 /**
  * Assert session contents
  *
  * @param string $expected The expected contents.
  * @param string $path The session data path. Uses Hash::get() compatible notation
  * @param string $message The failure message that will be appended to the generated message.
  * @return void
  */
 public function assertSession($expected, $path, $message = '')
 {
     if (empty($this->_requestSession)) {
         $this->fail('There is no stored session data. Perhaps you need to run a request?');
     }
     $result = $this->_requestSession->read($path);
     $this->assertEquals($expected, $result, 'Session content differs. ' . $message);
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:16,代码来源:IntegrationTestCase.php

示例3: user

 /**
  * Get the current user.
  *
  * Will prefer the static user cache over sessions. The static user
  * cache is primarily used for stateless authentication. For stateful authentication,
  * cookies + sessions will be used.
  *
  * @param string $key field to retrieve. Leave null to get entire User record
  * @return mixed User record. or null if no user is logged in.
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user
  */
 public static function user($key = null)
 {
     if (!empty(static::$_user)) {
         $user = static::$_user;
     } elseif (static::$sessionKey && Session::check(static::$sessionKey)) {
         $user = Session::read(static::$sessionKey);
     } else {
         return null;
     }
     if ($key === null) {
         return $user;
     }
     return Hash::get($user, $key);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:25,代码来源:AuthComponent.php

示例4: initialize

 public function initialize(array $config)
 {
     parent::initialize($config);
     // TODO: Change the autogenerated stub
     $session = new Session();
     $lang = $session->read('Config.language');
     $fieldLanguage = 'vie';
     switch ($lang) {
         case 'ja_JP':
             $fieldLanguage = 'jpn';
             break;
         case 'vi_VN':
             $fieldLanguage = 'vie';
             break;
         case 'en_US':
             $fieldLanguage = 'eng';
             break;
     }
     $this->fieldLanguage = $fieldLanguage;
     $curUser = $session->read('Core.Users');
     if ($curUser && $curUser->group == GROUP_ADMIN) {
         $this->cacheConfig = 'api_backend';
     }
     $this->jcApi = new JcApi(KEY_API, $this->fieldLanguage);
 }
开发者ID:nguyennghiem1205,项目名称:japan-circle,代码行数:25,代码来源:JcApiModelTable.php

示例5: setLanguage

 /**
  * Set the language for the user.
  *
  * @return void
  */
 public function setLanguage()
 {
     if ($this->_controller->Auth->user()) {
         //The user has already a valid language defined in the database.
         if ($this->_session->read('Auth.User.language') && isset($this->_locales[$this->_session->read('Auth.User.language')])) {
             //If the user has not the cookie, we set the cookie.
             if (!$this->_cookie->check('language') || $this->_cookie->read('language') != $this->_session->read('Auth.User.language')) {
                 $this->_cookie->write('language', $this->_session->read('Auth.User.language'));
             }
             //Stock the locale of the user.
             $this->_locale = $this->_session->read('Auth.User.language');
         }
     } else {
         //The user has a valid cookie.
         if ($this->_cookie->check('language') && isset($this->_locales[$this->_cookie->read('language')])) {
             $this->_locale = $this->_cookie->read('language');
         }
     }
     //The user want to change his language.
     if (isset($this->_controller->request->params['lang']) && isset($this->_locales[$this->_controller->request->params['lang']])) {
         //If the user is connected, we need to save the new language in the database and refresh his session.
         if ($this->_controller->Auth->user()) {
             $this->_controller->loadModel('Users');
             $user = $this->_controller->Users->find()->where(['id' => $this->_session->read('Auth.User.id')])->first();
             $user->language = $this->_controller->request->params['lang'];
             $this->_controller->Users->save($user);
             $this->_session->write('Auth.User.language', $this->_controller->request->params['lang']);
         }
         //Save the new language in the cookie.
         $this->_cookie->write('language', $this->_controller->request->params['lang']);
         $this->_locale = $this->_controller->request->params['lang'];
     }
     //Set the locale.
     I18n::locale($this->_locale);
 }
开发者ID:Xety,项目名称:Xeta,代码行数:40,代码来源:Language.php

示例6: redirectUrl

 /**
  * Get the URL a user should be redirected to upon login.
  *
  * Pass a URL in to set the destination a user should be redirected to upon
  * logging in.
  *
  * If no parameter is passed, gets the authentication redirect URL. The URL
  * returned is as per following rules:
  *
  *  - Returns the normalized URL from session Auth.redirect value if it is
  *    present and for the same domain the current app is running on.
  *  - If there is no session value and there is a config `loginRedirect`, the
  *    `loginRedirect` value is returned.
  *  - If there is no session and no `loginRedirect`, / is returned.
  *
  * @param string|array $url Optional URL to write as the login redirect URL.
  * @return string Redirect URL
  */
 public function redirectUrl($url = null)
 {
     if ($url !== null) {
         $redir = $url;
         $this->session->write('Auth.redirect', $redir);
     } elseif ($this->session->check('Auth.redirect')) {
         $redir = $this->session->read('Auth.redirect');
         $this->session->delete('Auth.redirect');
         if (Router::normalize($redir) === Router::normalize($this->_config['loginAction'])) {
             $redir = $this->_config['loginRedirect'];
         }
     } elseif ($this->_config['loginRedirect']) {
         $redir = $this->_config['loginRedirect'];
     } else {
         $redir = '/';
     }
     if (is_array($redir)) {
         return Router::url($redir + ['_base' => false]);
     }
     return $redir;
 }
开发者ID:aoliverio,项目名称:bookmarker-tutorial,代码行数:39,代码来源:AuthComponent.php

示例7: getUserFromRedirect

 /**
  * gets user data from facebook redirect
  *
  * @return array sanitized facebook user data
  */
 public function getUserFromRedirect()
 {
     $redirectUrl = $this->_session->read('Facebook.redirectUrl');
     $session = $this->_getSessionFromRedirect($redirectUrl);
     if ($session) {
         $userProfile = $this->getFullProfile($session);
         return $this->sanitizeResponse($userProfile);
     }
 }
开发者ID:codekanzlei,项目名称:cake-cktools,代码行数:14,代码来源:FacebookAuthComponent.php

示例8: set

 /**
  * Used to set a session variable that can be used to output messages in the view.
  * If you make consecutive calls to this method, the messages will stack (if they are
  * set with the same flash key)
  *
  * In your controller: $this->Flash->set('This has been saved');
  *
  * ### Options:
  *
  * - `key` The key to set under the session's Flash key
  * - `element` The element used to render the flash message. Default to 'default'.
  * - `params` An array of variables to make available when using an element
  * - `clear` A bool stating if the current stack should be cleared to start a new one
  * - `escape` Set to false to allow templates to print out HTML content
  *
  * @param string|\Exception $message Message to be flashed. If an instance
  *   of \Exception the exception message will be used and code will be set
  *   in params.
  * @param array $options An array of options
  * @return void
  */
 public function set($message, array $options = [])
 {
     $options += $this->config();
     if ($message instanceof Exception) {
         if (!isset($options['params']['code'])) {
             $options['params']['code'] = $message->getCode();
         }
         $message = $message->getMessage();
     }
     if (isset($options['escape']) && !isset($options['params']['escape'])) {
         $options['params']['escape'] = $options['escape'];
     }
     list($plugin, $element) = pluginSplit($options['element']);
     if ($plugin) {
         $options['element'] = $plugin . '.Flash/' . $element;
     } else {
         $options['element'] = 'Flash/' . $element;
     }
     $messages = [];
     if ($options['clear'] === false) {
         $messages = $this->_session->read('Flash.' . $options['key']);
     }
     $messages[] = ['message' => $message, 'key' => $options['key'], 'element' => $options['element'], 'params' => $options['params']];
     $this->_session->write('Flash.' . $options['key'], $messages);
 }
开发者ID:nrother,项目名称:cakephp,代码行数:46,代码来源:FlashComponent.php

示例9: generateToken

 /**
  * Manually add form tampering prevention token information into the provided
  * request object.
  *
  * @param \Cake\Network\Request $request The request object to add into.
  * @return bool
  */
 public function generateToken(Request $request)
 {
     if (isset($request->params['requested']) && $request->params['requested'] === 1) {
         if ($this->session->check('_Token')) {
             $request->params['_Token'] = $this->session->read('_Token');
         }
         return false;
     }
     $token = ['allowedControllers' => $this->_config['allowedControllers'], 'allowedActions' => $this->_config['allowedActions'], 'unlockedFields' => $this->_config['unlockedFields']];
     $this->session->write('_Token', $token);
     $request->params['_Token'] = ['unlockedFields' => $token['unlockedFields']];
     return true;
 }
开发者ID:yao-dev,项目名称:blog-mvc.github.io,代码行数:20,代码来源:SecurityComponent.php

示例10: read

 /**
  * Used to read a session values for a key or return values for all keys.
  *
  * In your controller: $this->Session->read('Controller.sessKey');
  * Calling the method without a param will return all session vars
  *
  * @param string $name the name of the session key you want to read
  * @return mixed value from the session vars
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#SessionComponent::read
  */
 public function read($name = null)
 {
     return Session::read($name);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:14,代码来源:SessionComponent.php

示例11: read

 /**
  * Used to read a session values for a key or return values for all keys.
  *
  * In your controller: $this->Session->read('Controller.sessKey');
  * Calling the method without a param will return all session vars
  *
  * @param string $name the name of the session key you want to read
  * @return mixed value from the session vars
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#SessionComponent::read
  */
 public function read($name = null)
 {
     return $this->_session->read($name);
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:14,代码来源:SessionComponent.php

示例12: testReadingSavedEmpty

 /**
  * testReadingSavedEmpty method
  *
  * @return void
  */
 public function testReadingSavedEmpty()
 {
     $session = new Session();
     $session->write('SessionTestCase', 0);
     $this->assertEquals(0, $session->read('SessionTestCase'));
     $session->write('SessionTestCase', '0');
     $this->assertEquals('0', $session->read('SessionTestCase'));
     $this->assertFalse($session->read('SessionTestCase') === 0);
     $session->write('SessionTestCase', false);
     $this->assertFalse($session->read('SessionTestCase'));
     $session->write('SessionTestCase', null);
     $this->assertEquals(null, $session->read('SessionTestCase'));
 }
开发者ID:Slayug,项目名称:castor,代码行数:18,代码来源:SessionTest.php

示例13: translate

 /**
  * Used by the translation functions in basics.php
  * Returns a translated string based on current language and translation files stored in locale folder
  *
  * @param string $singular String to translate
  * @param string $plural Plural string (if any)
  * @param string $domain Domain The domain of the translation. Domains are often used by plugin translations.
  *    If null, the default domain will be used.
  * @param int $category Category The integer value of the category to use.
  * @param int $count Count Count is used with $plural to choose the correct plural form.
  * @param string $language Language to translate string to.
  *    If null it checks for language in session followed by Config.language configuration variable.
  * @return string translated string.
  * @throws \Cake\Error\Exception When '' is provided as a domain.
  */
 public static function translate($singular, $plural = null, $domain = null, $category = self::LC_MESSAGES, $count = null, $language = null)
 {
     $_this = I18n::getInstance();
     if (strpos($singular, "\r\n") !== false) {
         $singular = str_replace("\r\n", "\n", $singular);
     }
     if ($plural !== null && strpos($plural, "\r\n") !== false) {
         $plural = str_replace("\r\n", "\n", $plural);
     }
     if (is_numeric($category)) {
         $_this->category = $_this->_categories[$category];
     }
     if (empty($language)) {
         if (Session::started()) {
             $language = Session::read('Config.language');
         }
         if (empty($language)) {
             $language = Configure::read('Config.language');
         }
     }
     if ($_this->_lang && $_this->_lang !== $language || !$_this->_lang) {
         $lang = $_this->l10n->get($language);
         $_this->_lang = $lang;
     }
     if ($domain === null) {
         $domain = static::$defaultDomain;
     }
     if ($domain === '') {
         throw new Exception('You cannot use "" as a domain.');
     }
     $_this->domain = $domain . '_' . $_this->l10n->lang;
     if (!isset($_this->_domains[$domain][$_this->_lang])) {
         $_this->_domains[$domain][$_this->_lang] = [];
         $_this->_domains[$domain][$_this->_lang] = Cache::read($_this->domain, '_cake_core_');
     }
     if (!isset($_this->_domains[$domain][$_this->_lang][$_this->category])) {
         $_this->_bindTextDomain($domain);
         Cache::write($_this->domain, $_this->_domains[$domain][$_this->_lang], '_cake_core_');
     }
     if ($_this->category === 'LC_TIME') {
         return $_this->_translateTime($singular, $domain);
     }
     if (!isset($count)) {
         $plurals = 0;
     } elseif (!empty($_this->_domains[$domain][$_this->_lang][$_this->category]["%plural-c"]) && $_this->_noLocale === false) {
         $header = $_this->_domains[$domain][$_this->_lang][$_this->category]["%plural-c"];
         $plurals = $_this->_pluralGuess($header, $count);
     } else {
         if ($count != 1) {
             $plurals = 1;
         } else {
             $plurals = 0;
         }
     }
     if (!empty($_this->_domains[$domain][$_this->_lang][$_this->category][$singular])) {
         if (($trans = $_this->_domains[$domain][$_this->_lang][$_this->category][$singular]) || $plurals && ($trans = $_this->_domains[$domain][$_this->_lang][$_this->category][$plural])) {
             if (is_array($trans)) {
                 if (isset($trans[$plurals])) {
                     $trans = $trans[$plurals];
                 } else {
                     trigger_error(sprintf('Missing plural form translation for "%s" in "%s" domain, "%s" locale. ' . ' Check your po file for correct plurals and valid Plural-Forms header.', $singular, $domain, $_this->_lang), E_USER_WARNING);
                     $trans = $trans[0];
                 }
             }
             if (strlen($trans)) {
                 return $trans;
             }
         }
     }
     if (!empty($plurals)) {
         return $plural;
     }
     return $singular;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:89,代码来源:I18n.php

示例14: flash

 /**
  * Used to render the message set in Controller::Session::setFlash()
  *
  * In your view: $this->Session->flash('somekey');
  * Will default to flash if no param is passed
  *
  * You can pass additional information into the flash message generation. This allows you
  * to consolidate all the parameters for a given type of flash message into the view.
  *
  * {{{
  * echo $this->Session->flash('flash', array('params' => array('class' => 'new-flash')));
  * }}}
  *
  * The above would generate a flash message with a custom class name. Using $attrs['params'] you
  * can pass additional data into the element rendering that will be made available as local variables
  * when the element is rendered:
  *
  * {{{
  * echo $this->Session->flash('flash', array('params' => array('name' => $user['User']['name'])));
  * }}}
  *
  * This would pass the current user's name into the flash message, so you could create personalized
  * messages without the controller needing access to that data.
  *
  * Lastly you can choose the element that is rendered when creating the flash message. Using
  * custom elements allows you to fully customize how flash messages are generated.
  *
  * {{{
  * echo $this->Session->flash('flash', array('element' => 'my_custom_element'));
  * }}}
  *
  * If you want to use an element from a plugin for rendering your flash message you can do that using the
  * plugin param:
  *
  * {{{
  * echo $this->Session->flash('flash', array(
  *   'element' => 'my_custom_element',
  *   'params' => array('plugin' => 'my_plugin')
  * ));
  * }}}
  *
  * @param string $key The [Message.]key you are rendering in the view.
  * @param array $attrs Additional attributes to use for the creation of this flash message.
  *    Supports the 'params', and 'element' keys that are used in the helper.
  * @return string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#SessionHelper::flash
  */
 public function flash($key = 'flash', $attrs = [])
 {
     if (!Session::check('Message.' . $key)) {
         return '';
     }
     $flash = Session::read('Message.' . $key);
     $message = $flash['message'];
     unset($flash['message']);
     if (!empty($attrs)) {
         $flash = array_merge($flash, $attrs);
     }
     if ($flash['element'] === 'default') {
         $class = 'message';
         if (!empty($flash['params']['class'])) {
             $class = $flash['params']['class'];
         }
         $out = $this->formatTemplate('flash', ['class' => $class, 'key' => $key, 'message' => $message]);
     } elseif (!$flash['element']) {
         $out = $message;
     } else {
         $options = array();
         if (isset($flash['params']['plugin'])) {
             $options['plugin'] = $flash['params']['plugin'];
         }
         $tmpVars = $flash['params'];
         $tmpVars['message'] = $message;
         $out = $this->_View->element($flash['element'], $tmpVars, $options);
     }
     Session::delete('Message.' . $key);
     return $out;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:78,代码来源:SessionHelper.php


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