A time ago, when I wrote an API about mobile apps, it was always a query_string address, and it was a act parameter that distinguishes all the actions, which makes developers look more cost-sensitive. Originally wanted to be rewritten as "? c=controller&m=method&type=3&id=1" This form, using the M parameter to load the file and instantiate, and later looked at the Sina Weibo API is the address is routed. Also decided to follow suit to address routing. Originally the CI framework itself with the routing effect, but because the consideration is to write the API, want to write a little more pure.
Support for default controller (index) and Method (index):
index.phpindex.php/controllerindex.php/controller/methodindex.php/controller/method/prarme1/value1index.php/ Controller/method/param1/value1/param2/value2 .....
*//The $se_string should be filtered. $ary _url=array (' controller ' = ' index ', ' method ' = ' index ', ' Pramers ' =>array ());//var_dump ($ary _url); $ Ary_se=explode ('/', $SE _string), $se _count=count ($ary _se);//Routing control if ($se _count==1 and $ary _se[0]!= ") {$ary _url[' Controller ']= $ary _se[0];} else if ($se _count>1) {//Calculate the following parameters, Key-value $ary _url[' controller ']= $ary _se[0]; $ary _url[' method ']= $ary _se[1]; if ($se _count>2 and $se _count%2!=0) {//Does not form Key-value form die (' parameter error '); }else{for ($i =2; $i < $se _count; $i = $i +2) {$ary _kv_hash=array (strtolower ($ary _se[$i]) + $ary _se[$i +1] ); $ary _url[pramers]=array_merge ($ary _url[pramers], $ary _kv_hash); }}} $module _name= $ary _url[' controller '] $module _file=module_dir. $module _name. Class.php ';//echo $module _file; $method _name= $ary _url[' method '];if (file_exists ($module _file)) {Include ($module _ file); $obj _module=new $module _name (); Instantiate module M if (!method_exists ($obj _module, $method _name)) {diE (' method not present '); }else{if (is_callable (Array ($obj _module, $method _name)) {//whether the method can be called//var_dump ($ary _url[pramers]); $get _return= $obj _module-> $method _name ($ary _url[pramers]); Execute the A method and pass an array of key-value parameters past if (!is_null ($get _return)) {//return value is not empty var_dump ($get _return); }}else{die (' The method cannot be called '); }}}else{die (' module file does not exist ');}? >
http://www.bkjia.com/PHPjc/752353.html www.bkjia.com true http://www.bkjia.com/PHPjc/752353.html techarticle some time ago wrote a mobile app API, has been used query_string this address, but also according to an act parameter to distinguish all the actions, this makes the developer look than ...