本文整理汇总了PHP中Cake\Network\Session::write方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::write方法的具体用法?PHP Session::write怎么用?PHP Session::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Network\Session
的用法示例。
在下文中一共展示了Session::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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' => []]]]]);
}
示例2: 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);
}
示例3: 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']);
}
示例4: 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);
}
示例5: set
/**
* Used to set a session variable that can be used to output messages in the view.
*
* 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
*
* @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) {
$options['params'] += ['code' => $message->getCode()];
$message = $message->getMessage();
}
list($plugin, $element) = pluginSplit($options['element']);
if ($plugin) {
$options['element'] = $plugin . '.Flash/' . $element;
} else {
$options['element'] = 'Flash/' . $element;
}
$this->_session->write('Flash.' . $options['key'], ['message' => $message, 'key' => $options['key'], 'element' => $options['element'], 'params' => $options['params']]);
}
示例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;
}
示例7: 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);
}
示例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->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]]]]);
}
示例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->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'))));
}
示例10: 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;
}
示例11: setFlash
/**
* Used to set a session variable that can be used to output messages in the view.
*
* In your controller: $this->Session->setFlash('This has been saved');
*
* Additional params below can be passed to customize the output, or the Message.[key].
* You can also set additional parameters when rendering flash messages. See SessionHelper::flash()
* for more information on how to do that.
*
* @param string $message Message to be flashed
* @param string $element Element to wrap flash message in.
* @param array $params Parameters to be sent to layout as view variables
* @param string $key Message key, default is 'flash'
* @return void
* @link http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#creating-notification-messages
*/
public function setFlash($message, $element = 'default', array $params = array(), $key = 'flash')
{
Session::write('Message.' . $key, compact('message', 'element', 'params'));
}
示例12: setFlash
/**
* Used to set a session variable that can be used to output messages in the view.
*
* In your controller: $this->Session->setFlash('This has been saved');
*
* Additional params below can be passed to customize the output, or the Message.[key].
* You can also set additional parameters when rendering flash messages. See SessionHelper::flash()
* for more information on how to do that.
*
* @param string $message Message to be flashed
* @param string $element Element to wrap flash message in.
* @param array $params Parameters to be sent to layout as view variables
* @param string $key Message key, default is 'flash'
* @return void
* @deprecated 3.0 Use FlashComponent::set() instead.
* @link http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#creating-notification-messages
*/
public function setFlash($message, $element = null, array $params = array(), $key = 'flash')
{
$this->_session->write('Flash.' . $key, ['message' => $message, 'key' => $key, 'element' => $element, 'params' => $params]);
}
示例13: setUser
/**
* Set provided user info to session as logged in user.
*
* The user record is written to the session key specified in AuthComponent::$sessionKey.
* The session id will also be changed in order to help mitigate session replays.
*
* @param array $user Array of user data.
* @return void
* @link http://book.cakephp.org/3.0/en/controllers/components/authentication.html#identifying-users-and-logging-them-in
*/
public function setUser(array $user)
{
$this->session->renew();
$this->session->write($this->sessionKey, $user);
}
示例14: write
/**
* Used to write a value to a session key.
*
* In your controller: $this->Session->write('Controller.sessKey', 'session value');
*
* @param string $name The name of the key your are setting in the session.
* This should be in a Controller.key format for better organizing
* @param string|null $value The value you want to store in a session.
* @return void
*/
public function write($name, $value = null)
{
$this->_session->write($name, $value);
}
示例15: 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');
}