/** * index 函数,当用户的访问URI指定了控制器,而没有指定方法名时,Printemps Framework 将会自动调用 index() 方法 * @return none */ public function index() { global $param; /** * 如果需要加载视图,可以用 parent::loadView() 函数,带上视图参数名称 * 例如要加载 /View/index/index.php,因为 indexController 是当前类,所以可以不带第二个参数:loadView('index.php'); * 如果要加载 helloController 类下的 index.php,需要将此文件放在/View/hello/index.php,然后使用以下方法调用: * loadView('index.php','helloController') */ parent::loadView('index.php'); echo Printemps_Fliter::fliteScirpt("<script>alert('XSS');</script>"); }
/** * 快速引入 css/js/图片 * @param string/array $filename 文件名 * @param string $class 样式名称 * @return none/boolean */ public function import($filename, $class = '') { $link = Printemps::parseURL(); $assetPath = str_replace(APP_ROOT_PATH . '/', "", APP_STATIC_PATH); if (!is_array($filename)) { $this->importChildren($link, $assetPath, $filename, $class); } else { foreach ($filename as $value) { $this->importChildren($link, $assetPath, $value, $class); } } }
<?php /** * Printemps Framework - Lightly PHP Framework based on PHP 5.3+ * Copyright(c) 2015 Printemps Framework DevTeam * KiraInmoe, minami@kotori.ovh, https://www.imim.pw * Know more about Printemps Framework please visit https://printemps.kotori.ovh/ */ require 'config.inc.php'; Printemps::Init(array("session" => true, "router" => true));
<?php require dirname(__FILE__) . '/../Printemps.php'; $printemps = Printemps::init(array("database" => array("host" => "localhost", "user" => "root", "password" => "root", "name" => "printemps", "port" => 3306, "encode" => "utf8", "method" => "mysqli"), "initial" => array("APP_ROOT_DIR" => dirname(__FILE__), "APP_NAME" => "printemps", "APP_VERSION" => "alpha", "APP_DEBUG_MODE" => true, "APP_ENTRY_MODE" => 2), "router" => array("class" => array("example" => "index"), "method" => array("index:example" => "index"))));
function __construct() { parent::__construct(); }
/** * Printemps initialization function * * @param array $cfg config options * @return bool if Printemps has succeessfully inited, return true */ public static function init($cfg = array()) { $basepath = dirname(__FILE__); /* default config file */ $_default = array("APP_ROOT_DIR" => $basepath, "APP_DEPENDENCE" => $basepath . '/dependence/', "APP_VIEWS" => $basepath . '/dependence/views/', "APP_CACHES" => $basepath . '/dependence/caches/', "APP_PUBLIC" => $basepath . '/public', "APP_ASSETS" => $basepath . '/public/assets/', "APP_NAME" => "Printemps Application", "APP_VERSION" => "1", "APP_DEBUG_MODE" => false, "APP_ENTRY_MODE" => 1, "APP_ERROR_HANDLER" => false); foreach ($_default as $key => $value) { if (isset($cfg['initial'][$key])) { define($key, $cfg['initial'][$key]); } else { define($key, $value); } } /** Register Autoload method*/ self::registerAutoload(); if (APP_ERROR_HANDLER) { set_error_handler(APP_ERROR_HANDLER, E_CORE_ERROR ^ E_USER_ERROR); } else { set_error_handler(array("Printemps_Exception", "halt"), E_CORE_ERROR ^ E_USER_ERROR); } set_error_handler(array("Printemps_Exception", "notice"), E_WARNING ^ E_NOTICE); //for notice / warning set_exception_handler(array("Printemps_Exception", "halt")); //for exception Printemps_Config::write($_default); Printemps_Config::write($cfg); isset($cfg['router']) && $cfg['router'] ? Printemps_Router::dispatch() : false; $_printemps = Printemps::getInstance(); return $_printemps; }