2012-07-26 45 views
2

Cake 1.x有一個允許Session.database的配置選項,以便可以爲會話表使用完全不同的機器/數據庫。在Cake 2.0中,默認的core.php配置文件似乎不再具有該選項。將Cake 2.x配置爲爲會話使用不同的數據庫

如果不編寫自定義會話處理程序,這仍然是可能的嗎?

/** 
* Session configuration. 
* 
* Contains an array of settings to use for session configuration. The defaults key is 
* used to define a default preset to use for sessions, any settings declared here will override 
* the settings of the default config. 
* 
* ## Options 
* 
* - `Session.cookie` - The name of the cookie to use. Defaults to 'CAKEPHP' 
* - `Session.timeout` - The number of minutes you want sessions to live for. This timeout is handled by CakePHP 
* - `Session.cookieTimeout` - The number of minutes you want session cookies to live for. 
* - `Session.checkAgent` - Do you want the user agent to be checked when starting sessions? You might want to set the 
* value to false, when dealing with older versions of IE, Chrome Frame or certain web-browsing devices and AJAX 
* - `Session.defaults` - The default configuration set to use as a basis for your session. 
* There are four builtins: php, cake, cache, database. 
* - `Session.handler` - Can be used to enable a custom session handler. Expects an array of of callables, 
* that can be used with `session_save_handler`. Using this option will automatically add `session.save_handler` 
* to the ini array. 
* - `Session.autoRegenerate` - Enabling this setting, turns on automatic renewal of sessions, and 
* sessionids that change frequently. See CakeSession::$requestCountdown. 
* - `Session.ini` - An associative array of additional ini values to set. 
* 
* The built in defaults are: 
* 
* - 'php' - Uses settings defined in your php.ini. 
* - 'cake' - Saves session files in CakePHP's /tmp directory. 
* - 'database' - Uses CakePHP's database sessions. 
* - 'cache' - Use the Cache class to save sessions. 
* 
* To define a custom session handler, save it at /app/Model/Datasource/Session/<name>.php. 
* Make sure the class implements `CakeSessionHandlerInterface` and set Session.handler to <name> 
* 
* To use database sessions, run the app/Config/Schema/sessions.php schema using 
* the cake shell command: cake schema create Sessions 
* 
*/ 

回答

2

從我自己的員工:

「 好了,路似乎是創建一個自定義‘會話處理程序’模式使用這樣的設置:

Configure::write('Session.handler.model', 'CustomSession'); 

哪裏CustomSession.php模型文件具有配置'會話'是我添加到我的config/database.php文件的配置:

<?php 
class CustomSession extends AppModel { 
    var $useDbConfig = 'sessions'; 
    var $useTable = 'cake_sessions'; 
} 

「不幸的是,該功能的Cake文檔非常糟糕。 Cake.handler實際上定義了Session的行爲,它不同於Cake Session.handler.model。默認情況下,handler.model是AppModel(在Cake內部,請參閱lib/Cake/Model/Session/DatabaseSession.php第48行__construct()函數 - 它實例化$ this - > _ model。如果您沒有設置自定義模型,它會實例化爲AppModel,試着放入一個調試來看看它的實際運行情況。)我鏈接到的稀疏文檔將其解釋爲

以上將告訴CakeSession使用內置的'數據庫'默認值,並指定稱爲CustomSession的模型將成爲將會話信息保存到數據庫的代表。

而且,看到http://api20.cakephp.org/class/database-session _model屬性: 「參考模型處理會話數據」

所以這就是如何/爲什麼工程....

-AWD」

相關問題