Phpcms source code parameter param configuration

Source: Internet
Author: User
The preceding section describes application. class. php in phpcms source code parameter param configuration. when the application class is loaded, the route is initialized. Some functions in param. class. php are called .? Now let's take a look at the param. class. php class. in this class, we first define a private variable to receive route configurations. Route configuration private phpcms source code parameter param configuration

As mentioned above, application. class. php initializes the route when the application class is loaded.

Some functions in param. class. php are called.

?

Now let's take a look at the param. class. php class.

In this class, a private variable is defined to receive route configurations.

// Route configuration private $ route_config = '';

? Let's take a look at its constructor.

Public function _ construct () {if (! Get_magic_quotes_gpc () {$ _ POST = new_addslashes ($ _ POST); $ _ GET = new_addslashes ($ _ GET); $ _ REQUEST = new_addslashes ($ _ REQUEST ); $ _ COOKIE = new_addslashes ($ _ COOKIE);} // initialize the private variable $ route_config from the system configuration file route. get $ this-> route_config = pc_base: load_config ('Route ', SITE_URL) in php )? Pc_base: load_config ('Route ', SITE_URL): pc_base: load_config ('Route', 'default'); // If route. if the $ _ POST global variable is configured in php, the key-value pair is read. the key-value pair corresponds to 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 ;}// if route. if the $ _ GET global variable is configured in php, the key-value pair is read. the key-value pair corresponds to 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 ;}} // if the page is passed in the get parameter passing method, the request is processed if (isset ($ _ GET ['Page']). {$ _ GET ['Page'] = max (intval ($ _ GET ['Page']), 1 ); $ _ GET ['Page'] = min ($ _ GET ['Page'], 1000000000);} return true ;}

? Original route. php file

 Array (* 'M' => 'phpcms ', * 'C' => 'index', * 'a' => 'init ', * 'data' => array (* 'post' => array (* 'catid' => 1 *), * 'get' => array (* 'contentid' => 1 *) * in the base, "m" is the model, and "c" is the controller, "a" is an event, and "data" is another additional parameter. * Data is a two-dimensional array. you can set the default parameters of POST and GET. POST and GET correspond to the hyper-global variables $ _ POST and $ _ GET in PHP respectively. In the program, you can use $ _ POST ['catid'] to obtain the value of the array in POST under data. * The parameter levels set in data are relatively low. If an external program submits a variable with the same name, it overwrites the value set in the configuration file. For example, * if the external program POST a variable catid = 2, the value you get using $ _ POST in the program is 2, instead of 1 set in the configuration file. */Return array ('default' => array ('M' => 'content', 'C' => 'index ', 'A' => 'init '),);

?

As mentioned above, functions in the param class are called during application class initialization. let's take a look at the following:

Get model

/*** GET model */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 ;}}

?

Get controller

/*** GET controller */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 ;}}

?

Get events

/*** GET event */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 ($ )) {return $ this-> route_config ['A'];} else {if (is_string ($ a) return $ ;}}

?

This class also defines three functions for calling.

/*** Security processing function * processes m, a, c */private function safe_deal ($ str) {return str_replace (array ('/','. '), '', $ str );}

? Cookies

/*** Set cookie * @ param string $ var variable name * @ param string $ value variable value * @ param int $ time Expiration time */public static function set_cookie ($ var, $ value = '', $ time = 0) {$ time = $ time> 0? $ Time: ($ value = ''? SYS_TIME-3600: 0); $ s = $ _ SERVER ['server _ port'] = '20140901 '? 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, 'encoding'), $ time, pc_base: load_config ('system', 'Cookie _ path'), pc_base :: load_config ('system', 'Cookie _ domain '), $ s) ;}} else {setcookie ($ var, sys_auth ($ value, 'encoding'), $ time, pc_base: load_config ('system', 'Cookie _ path'), pc_base: load_config ('system', 'Cookie _ domain '), $ s );}}

?

/*** Get the cookie variable set through set_cookie * @ param string $ var variable name * @ param string $ default value * @ return mixed returns the cookie value, otherwise, false */public static function get_cookie ($ var, $ default = '') {$ var = pc_base: load_config ('system', 'Cookie _ pre') is returned '). $ var; return isset ($ _ COOKIE [$ var])? Sys_auth ($ _ COOKIE [$ var], 'decode'): $ default ;}

?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.