コード例 #1
0
    /**
     * if this is called, the published version of the page
     * will include and initialize the DB::query stub
     * and connect to the main silverstripe database.
     * This allows limited use of DB::query() in both a live
     * and published context.
     */
    public static function require_silverstripe_db()
    {
        global $databaseConfig;
        if (self::is_publishing() && !self::$silverstripe_db_included) {
            self::$silverstripe_db_included = true;
            self::$init_code[] = '
				$databaseConfig = ' . var_export($databaseConfig, true) . ';
				require_once "' . dirname(dirname(__FILE__)) . '/dummy_classes/LivePubDB.php";
				DB::init();
			';
        }
    }