2

Cake 1.x にはSession.database、完全に異なるマシン/データベースをセッションテーブルに使用できるようにする構成オプションがありました。Cake 2.0 では、デフォルトの core.php 設定ファイルにそのオプションがないように見えます。

カスタム セッション ハンドラを作成しなくても、これは可能ですか?

/**
 * 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
 *
 */
4

1 に答える 1

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 のドキュメントはひどいものです。Session の動作を実際に定義する Cake の Session.handler は、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」

于 2012-08-23T05:15:06.767 に答える