phpcms源碼 參數param配備

來源:互聯網
上載者:User
phpcms源碼 參數param配置

上節說到了application.class.php,當application類載入時,就會對路由進行初始化。

其中調用了param.class.php中的一些函數。

?

現在就來看一下param.class.php這個類

此類中,首先是定義了一個私人變數,用來接收路由配置。

//路由配置private $route_config = '';

?看一下它的建構函式吧。

public function __construct() {if(!get_magic_quotes_gpc()) {$_POST = new_addslashes($_POST);$_GET = new_addslashes($_GET);$_REQUEST = new_addslashes($_REQUEST);$_COOKIE = new_addslashes($_COOKIE);}//初始化私人變數$route_config,從系統設定檔route.php中擷取$this->route_config = pc_base::load_config('route', SITE_URL) ? pc_base::load_config('route', SITE_URL) : pc_base::load_config('route', 'default');//若route.php中配置了$_POST全域變數,則讀取,索引值對依依對應if(isset($this->route_config['data']['POST']) && is_array($this->route_config['data']['POST'])) {foreach($this->route_config['data']['POST'] as $_key => $_value) {if(!isset($_POST[$_key])) $_POST[$_key] = $_value;}}//若route.php中配置了$_GET全域變數,則讀取,索引值對依依對應if(isset($this->route_config['data']['GET']) && is_array($this->route_config['data']['GET'])) {foreach($this->route_config['data']['GET'] as $_key => $_value) {if(!isset($_GET[$_key])) $_GET[$_key] = $_value;}}//get傳參方式中傳遞了分頁(page),則對其進行處理if(isset($_GET['page'])) {$_GET['page'] = max(intval($_GET['page']),1);$_GET['page'] = min($_GET['page'],1000000000);}return true;}

?route.php 原始檔案

array( * 'm'=>'phpcms',  * 'c'=>'index',  * 'a'=>'init',  * 'data'=>array( * 'POST'=>array( * 'catid'=>1 * ), * 'GET'=>array( * 'contentid'=>1 * ) * ) * ) * 基中“m”為模型,“c”為控制器,“a”為事件,“data”為其他附加參數。 * data為一個二維數組,可設定POST和GET的預設參數。POST和GET分別對應PHP中的$_POST和$_GET兩個超全域變數。在程式中您可以使用$_POST['catid']來得到data下面POST中的數組的值。 * data中的所設定的參數等級比較低。如果外部程式有提交相同的名字的變數,將會覆蓋設定檔中所設定的值。如: * 外部程式POST了一個變數catid=2那麼你在程式中使用$_POST取到的值是2,而不是設定檔中所設定的1。 */return array('default'=>array('m'=>'content', 'c'=>'index', 'a'=>'init'),);

?

上面講到了application類初始化中調用了param類中的函數,下面來看一下

擷取模型

/** * 擷取模型 */public function route_m() {$m = isset($_GET['m']) && !empty($_GET['m']) ? $_GET['m'] : (isset($_POST['m']) && !empty($_POST['m']) ? $_POST['m'] : '');$m = $this->safe_deal($m);if (empty($m)) {return $this->route_config['m'];} else {if(is_string($m)) return $m;}}

?

擷取控制器

/** * 擷取控制器 */public function route_c() {$c = isset($_GET['c']) && !empty($_GET['c']) ? $_GET['c'] : (isset($_POST['c']) && !empty($_POST['c']) ? $_POST['c'] : '');$c = $this->safe_deal($c);if (empty($c)) {return $this->route_config['c'];} else {if(is_string($c)) return $c;}}

?

擷取事件

/** * 擷取事件 */public function route_a() {$a = isset($_GET['a']) && !empty($_GET['a']) ? $_GET['a'] : (isset($_POST['a']) && !empty($_POST['a']) ? $_POST['a'] : '');$a = $this->safe_deal($a);if (empty($a)) {return $this->route_config['a'];} else {if(is_string($a)) return $a;}}

?

該類中還定義了三個函數,供調用

/** * 安全處理函數 * 處理m,a,c */private function safe_deal($str) {return str_replace(array('/', '.'), '', $str);}

?cookies函數

/** * 設定 cookie * @param string $var     變數名 * @param string $value   變數值 * @param int $time    到期時間 */public static function set_cookie($var, $value = '', $time = 0) {$time = $time > 0 ? $time : ($value == '' ? SYS_TIME - 3600 : 0);$s = $_SERVER['SERVER_PORT'] == '443' ? 1 : 0;$var = pc_base::load_config('system','cookie_pre').$var;$_COOKIE[$var] = $value;if (is_array($value)) {foreach($value as $k=>$v) {setcookie($var.'['.$k.']', sys_auth($v, 'ENCODE'), $time, pc_base::load_config('system','cookie_path'), pc_base::load_config('system','cookie_domain'), $s);}} else {setcookie($var, sys_auth($value, 'ENCODE'), $time, pc_base::load_config('system','cookie_path'), pc_base::load_config('system','cookie_domain'), $s);}}

?

/** * 擷取通過 set_cookie 設定的 cookie 變數  * @param string $var 變數名 * @param string $default 預設值  * @return mixed 成功則返回cookie 值,否則返回 false */public static function get_cookie($var, $default = '') {$var = pc_base::load_config('system','cookie_pre').$var;return isset($_COOKIE[$var]) ? sys_auth($_COOKIE[$var], 'DECODE') : $default;}

?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.