4. Session系统

Session龩龨龧龦龢龞龜龚龗龖龒龐龍龋龇龃龂齾齻齸齵齳齰齬齩齵齳齦齦齣齻齟齛齙龋Drupal8齀齻齟齛Symfony龒Session鼷鼶龋鼵鼷鼶龜龚鼴鼲鼯鼬龋drupal8龩鼥鼢鼞鼜鼙鼖鼓鼐鼌鼊鼆龋龖鼂鼁Symfony龒Session鼷鼶黿黽黺黷黶黵黱php龒Session黮黪黩黧黦

php黵黱龒Session黤齻黢點黚黙鼶默黕龇龃齻齸黒黐齵齳龋黍黉黇黄黃黁龨龧黀麽齛龋麼php麸龒麷龜麵鼥龋齙麱麯齛黇麫麪黮黪黿齻齸麨麦麥麣麠Session龒麜麚龋麖麵麒麐龇龃齰齵齳麎 齵齳麊 齦齦龋黽黺麉黇麉Session麇麵麅麜麚龒黦

麜麚Session鼙7麀鹼鹹open, close, read, write, destroy, gc , create_sid龋鹪鹨麇黵黱齰php鼊鼆齰鹥麇齻齸麥麣麠黮黪齣麇齀齻齙黺龋齀齻session_set_save_handler()鹜齵鹘鹗鹓龋Session黮黪鹒黒鹎齻黍鹍鹼鹹齀齻齙黺鹉鹇麣麠龒鹆鹄鹁龇龃黒黐齵齳龋鸿鸽鸻鸸鸴鸰鸬麉 鸩鹼黙鸧 龋龩php5.4鸟鸝php麣麠齛Session鸜鼂黚鸚鸘SessionHandlerInterface麦鸐鼥鸚鸘龒鸌鸋麜麚 SessionHandler 龋齻齸麨麦麥鸊鹁麜麚鼵鸚鸘龋鸚鸘麣麠齛麦鼜7麀鹼鹹龋黍鹍鹼鹹黒鸇php鹉鹇麥鸆鹎齻龋鸃鸁齻齸鷾鷼龋php黒鷹鹎齻鷸鷶鷵鷲齟$_SESSION鷣鷠鷞鷛鷘鷖龋黍麀鸚鸘龒麜麚黍鷖鷹齙鷓鷏龃龇鸜鼂黚龋鼙齛齙黽黺鹒麨麦龩鷖鷋麜麚齵齳麊龃龇鹆鹄齦齦齛鷈

鷅鷋鷃麉黇麉Symfony龒Session鼷鼶麇鷂鷀鶽鶺龒龋黷麉黇鶷鶶黦

麫麀Session默黕鶲齻齸麱麯黇麀黕黇龒鶮鷋龋鶪 SessionInterface鸚鸘麣麠龋龩鹉鹇鶧鷏鶦鼲鹇鶧黦

SessionBagInterface 黦齵齳鶟鸚鸘龋齻鸽鹨鼂鶝鶛齻齸龒齵齳龋黍鷖鷓鶚鷏齵齳鶟鹨鼂黚

SessionStorageInterface 黦龇龃鸜鼂鸚鸘龋齻鸽鸜鼂齵齳龒龇龃齰Session ID鶧鶙齦龋黍鷖鷓鷏龇龃鹨鼂黚

齵齳鹨鼂黚鸌鸋麱麯齛鶘鼲鶗黦

AttributeBag 黦鶐鶍鶟龋鶊龚齀齻龒齵齳鹒龃麎龩黍鷖

FlashBag 黦鶅龃鶟龋鶁黉黇鹍鶀鵽齻鵻龋齵齳鵷鵵鸇鵲鵯黇鵫龋齻鹓鵪鵧

MetadataBag 黦鵡齵齳鶟龋齻鸽龃龇Session齵齳鵟鵝龒黇鹍鵡齵齳龋麖麵Session鵚鵘龒齾鵔齰鶝鹓齀齻齾鵔齰黱鵐鵌鵋

龩SessionBagInterface鸚鸘鷖鷋黽黺麨麦麉齟鶦麀鶐鶍黦Name鼌StorageKey龋Name鵅鼂鼁龋齙齻鸽鵄鵀黍麀齵齳鶟龋麼StorageKey麇鴾鷀鴺鴷鴶鴲麜齵齳鶟鷖鷋龒齵齳齣麇龇龃龩$_SESSION鷖鷋龋齵齳鶟鹨鼂黚鵟鵝鵷麇龇龃黇麀鴱齻鴭鴬龋鴩鴧龒齵齳龩$_SESSION[$StorageKey]鷖鷈鴝麀鶟齣黉鶁鴛$_SESSION龒黇麀鴚齵鼷龋黍鴖鹒麜麚齛Session鴓麨麦鼌鴲鴑鴐鶘鹼鴏鼶鴍鴉龋鶟麇麵麅鼌$_SESSION[$StorageKey]鸿鴆龒鴃鴶黍鹒麇鸚鸘鷖鷋initialize(array &$array)鹼鹹龒鳻鶺鷈

Symfony的Session组件

鷅鷋麉黇麉龇龃鹨鼂黚黦

Symfony鸌鸋麜麚齛黇麀龇龃鹨鼂黚黦NativeSessionStorage龋齙鳷鳴齛php龒黵黱Session齀齻龋齀齻php黵黱龒龇龃鸜鼂黚SessionHandlerInterface

黽黺龩鳲鳯鳮Session龒齾鳭麨麦鳬鳫麥麣麠龒龇龃鹨鼂黚鸐鶟鹨鼂黚龋鳪鼐鹜齵麵鷅黦

__construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)

龩鹪麱麯鳦麅鳢齵齾鳡鸚齀齻php黵黱黮黪龋鹪鳟龒麇齙鴬鳛鸇鶟鳴鳙齛鷋鶲黉鳖鹼鳕鷈

鳓鳐鳍鳊鹉鴉鳉鳇

麦鼜鹒麇Symfony龒Session鼷鼶黵鼂鷈

drupal8鼙鼖鼓鳅龋鶟鳂龇龃Session齟齵齳麊龋鸻鳐\core\lib\Drupal\Core\Session

齙鲼鸐齟齻齸鲸齸鸚鸘龋鲷鲴鲱鲭鲫

use Symfony\Component\HttpFoundation\Session\Storage\Session\Session;  
  
$Session=new Session();  
$Session->set($name, $value);

本书共71小节:

评论 (写第一个评论)