• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Network\Session类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: setUp

 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->View = new View();
     $session = new Session();
     $this->View->request = new Request(['session' => $session]);
     $this->Flash = new FlashHelper($this->View);
     $session->write(['Flash' => ['flash' => [['key' => 'flash', 'message' => 'This is a calling', 'element' => 'Flash/default', 'params' => []]], 'notification' => [['key' => 'notification', 'message' => 'This is a test of the emergency broadcasting system', 'element' => 'flash_helper', 'params' => ['title' => 'Notice!', 'name' => 'Alert!']]], 'classy' => [['key' => 'classy', 'message' => 'Recorded', 'element' => 'flash_classy', 'params' => []]], 'stack' => [['key' => 'flash', 'message' => 'This is a calling', 'element' => 'Flash/default', 'params' => []], ['key' => 'notification', 'message' => 'This is a test of the emergency broadcasting system', 'element' => 'flash_helper', 'params' => ['title' => 'Notice!', 'name' => 'Alert!']], ['key' => 'classy', 'message' => 'Recorded', 'element' => 'flash_classy', 'params' => []]]]]);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:14,代码来源:FlashHelperTest.php


示例2: setUp

 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->View = new View();
     $this->Session = new SessionHelper($this->View);
     Session::start();
     if (!Session::started()) {
         Session::start();
     }
     $_SESSION = array('test' => 'info', 'Message' => array('flash' => array('element' => 'default', 'params' => array(), 'message' => 'This is a calling'), 'notification' => array('element' => 'session_helper', 'params' => array('title' => 'Notice!', 'name' => 'Alert!'), 'message' => 'This is a test of the emergency broadcasting system'), 'classy' => array('element' => 'default', 'params' => array('class' => 'positive'), 'message' => 'Recorded'), 'bare' => array('element' => null, 'message' => 'Bare message', 'params' => array())), 'Deeply' => array('nested' => array('key' => 'value')));
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:16,代码来源:SessionHelperTest.php


示例3: 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


示例4: fromGlobals

 /**
  * {@inheritDoc}
  */
 public static function fromGlobals(array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null)
 {
     $request = parent::fromGlobals($server, $query, $body, $cookies, $files);
     list($base, $webroot) = static::getBase($request);
     $sessionConfig = (array) Configure::read('Session') + ['defaults' => 'php', 'cookiePath' => $webroot];
     $session = Session::create($sessionConfig);
     $request = $request->withAttribute('base', $base)->withAttribute('webroot', $webroot)->withAttribute('session', $session);
     if ($base) {
         $request = static::updatePath($base, $request);
     }
     return $request;
 }
开发者ID:nrother,项目名称:cakephp,代码行数:15,代码来源:ServerRequestFactory.php


示例5: getSession

 /**
  * Get instance of the session.
  *
  * @return \Cake\Network\Session
  */
 public function getSession()
 {
     if (!empty($this->cake['session'])) {
         return $this->cake['session'];
     }
     if (!empty($this->cake['request'])) {
         $this->cake['session'] = $this->cake['request']->session();
         return $this->cake['session'];
     }
     $config = (array) Configure::read('Session') + ['defaults' => 'php'];
     $this->cake['session'] = Session::create($config);
     return $this->cake['session'];
 }
开发者ID:cakephp,项目名称:codeception,代码行数:18,代码来源:Connector.php


示例6: 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


示例7: 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


示例8: setUp

 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->View = new View();
     $session = new Session();
     $this->View->request = new Request(['session' => $session]);
     $this->Session = new SessionHelper($this->View);
     $session->write(array('test' => 'info', 'Flash' => array('flash' => array('type' => 'info', 'params' => array(), 'message' => 'This is a calling'), 'notification' => array('type' => 'info', 'params' => array('title' => 'Notice!', 'name' => 'Alert!', 'element' => 'session_helper'), 'message' => 'This is a test of the emergency broadcasting system'), 'classy' => array('type' => 'success', 'params' => array('class' => 'positive'), 'message' => 'Recorded'), 'incomplete' => ['message' => 'A thing happened']), 'Deeply' => array('nested' => array('key' => 'value'))));
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:14,代码来源:SessionHelperTest.php


示例9: setUp

 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->View = new View();
     $session = new Session();
     $this->View->request = new Request(['session' => $session]);
     $this->Flash = new FlashHelper($this->View);
     $session->write(['Flash' => ['flash' => ['key' => 'flash', 'message' => 'This is a calling', 'element' => 'Flash/default', 'params' => []], 'error' => ['key' => 'error', 'message' => 'This is error', 'element' => 'Flash/error', 'params' => []], 'custom1' => ['key' => 'custom1', 'message' => 'This is custom1', 'element' => 'Flash/warning', 'params' => []], 'custom2' => ['key' => 'custom2', 'message' => 'This is custom2', 'element' => 'Flash/default', 'params' => ['class' => 'foobar']], 'custom3' => ['key' => 'custom3', 'message' => 'This is <a href="#">custom3</a>', 'element' => 'Flash/default', 'params' => ['escape' => false]]]]);
 }
开发者ID:olafthelofty,项目名称:carenta,代码行数:14,代码来源:FlashHelperTest.php


示例10: login

 public function login()
 {
     $this->viewBuilder()->layout('login');
     //If a user is already logged in, redirect them to their profile.
     if ($this->Auth->user()) {
         $this->redirect($this->referer());
     }
     $session = new Session();
     if ($this->request->is('post')) {
         if (isset($this->request->data['referred'])) {
             $session->write('Redirect.login', $this->referer());
         }
         $user = $this->Auth->identify();
         if ($user) {
             $this->Auth->setUser($user);
             $this->_setCookie();
             return $this->redirect($this->Auth->redirectUrl());
         }
         $this->Flash->error('Invalid username or password, try again');
     }
 }
开发者ID:birdy247,项目名称:UsersManager,代码行数:21,代码来源:UsersController.php


示例11: 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


示例12: _getUserId

 /**
  * Gets current User's ID.
  *
  * @return int User ID, zero if not found
  */
 protected function _getUserId()
 {
     $callable = $this->config('idCallable');
     $id = 0;
     if (is_string($callable)) {
         $session = Session::create();
         $id = $session->read($callable);
     } elseif (is_callable($callable)) {
         $id = $callable();
     }
     return (int) $id;
 }
开发者ID:quickapps-plugins,项目名称:user,代码行数:17,代码来源:WhoDidItBehavior.php


示例13: testBadEngine

 /**
  * Tests instantiating a missing engine
  *
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The class "Derp" does not exist and cannot be used as a session engine
  * @return void
  */
 public function testBadEngine()
 {
     $session = new Session();
     $session->engine('Derp');
 }
开发者ID:Slayug,项目名称:castor,代码行数:12,代码来源:SessionTest.php


示例14: testSetLanguageWithSession

 /**
  * testSetLanguageWithSession method
  *
  * @return void
  */
 public function testSetLanguageWithSession()
 {
     Session::start();
     Session::write('Config.language', 'po');
     $singular = $this->_singular();
     $this->assertEquals('Po (translated)', $singular);
     $plurals = $this->_plural();
     $this->assertTrue(in_array('0 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('1 is 1 (po translated)', $plurals));
     $this->assertTrue(in_array('2 is 2-4 (po translated)', $plurals));
     $this->assertTrue(in_array('3 is 2-4 (po translated)', $plurals));
     $this->assertTrue(in_array('4 is 2-4 (po translated)', $plurals));
     $this->assertTrue(in_array('5 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('6 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('7 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('8 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('9 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('10 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('11 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('12 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('13 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('14 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('15 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('16 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('17 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('18 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('19 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('20 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('21 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('22 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('23 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('24 everything else (po translated)', $plurals));
     $this->assertTrue(in_array('25 everything else (po translated)', $plurals));
     Session::delete('Config.language');
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:40,代码来源:I18nTest.php


示例15: createFromGlobals

 /**
  * Wrapper method to create a new request from PHP superglobals.
  *
  * Uses the $_GET, $_POST, $_FILES, $_COOKIE, $_SERVER, $_ENV and php://input data to construct
  * the request.
  *
  * @return \Cake\Network\Request
  */
 public static function createFromGlobals()
 {
     list($base, $webroot) = static::_base();
     $sessionConfig = (array) Configure::read('Session') + ['defaults' => 'php', 'cookiePath' => $webroot];
     $config = ['query' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'cookies' => $_COOKIE, 'environment' => $_SERVER + $_ENV, 'base' => $base, 'webroot' => $webroot, 'session' => Session::create($sessionConfig)];
     $config['url'] = static::_url($config);
     return new static($config);
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:16,代码来源:Request.php


示例16: testSessionId

 /**
  * testSessionId method
  *
  * @return void
  */
 public function testSessionId()
 {
     unset($_SESSION);
     $Session = new SessionComponent($this->ComponentRegistry);
     Session::start();
     $this->assertEquals(session_id(), $Session->id());
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:12,代码来源:SessionComponentTest.php


示例17: started

 /**
  * Returns a bool, whether or not the session has been started.
  *
  * @return bool
  */
 public function started()
 {
     return Session::started();
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:9,代码来源:SessionComponent.php


示例18: 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


示例19: getLoginUrl

 /**
  * provides facebook login URL
  * used by webapp
  *
  * @param  string $redirectUrl destination to be redirect to after calling the login URL
  * @return string facebook login url
  */
 public function getLoginUrl($redirectUrl = null)
 {
     $this->_session->write('Facebook.redirectUrl', $redirectUrl);
     $facebookRedirectLoginHelper = $this->_getFacebookRedirectLoginHelper($redirectUrl);
     return $facebookRedirectLoginHelper->getLoginUrl(['email', 'user_birthday']);
 }
开发者ID:codekanzlei,项目名称:cake-cktools,代码行数:13,代码来源:FacebookAuthComponent.php


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Email\Email类代码示例发布时间:2022-05-23
下一篇:
PHP Network\Response类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap