Yii2 中的會話檔案存盤在哪里?我需要知道確切的位置。有創建會話資料庫的選項。
uj5u.com熱心網友回復:
默認會話保存路徑是'/tmp'. 鏈接
該路徑可通過getSavePath()會話類檔案中的方法訪問(yii2)
- @property string $savePath 當前會話保存路徑,默認為 '/tmp'。
例如,在 xampp 軟體(localhost)中,轉到以下檔案夾(默認)
myDrive:\xampp\tmp // The drive where the software is installed
默認情況下通過session_save_path方法獲取。這取決于php.ini檔案的設定。但是session.save_path="...\tmp"
你也可以通過.htaccess檔案來配置
要調整 Yii2,您可以執行以下操作。In the config web file
'components' => [
'session' => [
'name' => '_Session',
'savePath' => dirname(__DIR__) .'/sessions'
],
要保存在資料庫中(yii\web\DbSession),請參考此鏈接。
例子:
'session' => [
'class' => 'yii\web\DbSession',
'name' => 'mySession',
// 'db' => 'mydb', // the application component ID of the DB connection. Defaults to 'db'.
// 'sessionTable' => 'my_session', // session table name. Defaults to 'session'.
'timeout' => 30 * 24 * 3600,
'cookieParams' => ['httponly' => true, 'lifetime' => 3600 * 24],
'writeCallback' => function ($session) {
return [
// 'user_id' => Yii::$app->user->id,
// 'last_write' => time(),
];
},
],
writeCallback:在資料庫表中創建更多資料和列
祝你好運
uj5u.com熱心網友回復:
Yii2 默認將會話檔案存盤在@app/runtime/data檔案夾中。
如果你想使用資料庫,那么 yii2 指南是很好的資源。檢查此鏈接:https ://www.yiiframework.com/doc/guide/2.0/en/runtime-sessions-cookies#custom-session-storage 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/457914.html
