小編給大家分享一下實(shí)現(xiàn)一個(gè)簡(jiǎn)單php框架的示例,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
為金水等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及金水網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都做網(wǎng)站、網(wǎng)站建設(shè)、金水網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專(zhuān)業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
首先看一下現(xiàn)有的文件目錄

DOCUMENT_ROOR 為 /home/www目錄
然后看一下入口文件的內(nèi)容
<?php
$controll_action = $_GET['_ca_'];
$params = explode('/',$controll_action);
$params_count = count($params);
$otherParams = $params;
if($params_count>1) {
$controller = $params[0];
$action = $params[1];
unset($params[0]);
unset($params[1]);
}else if($params_count==1) {
$controller = $params[0];
$action = 'index';
unset($params[0]);
}
$filename = strtolower($controller).'.php';
$controller_path = $_SERVER['DOCUMENT_ROOT'].'/application/controllers/';
if(!file_exists($controller_path.$filename)) {
throw new Exception('controller '.$filename.' is not exists!');
return;
}
include($controller_path.$filename);
$classname = ucfirst($controller);
if(!class_exists($classname)) {
throw new Excpetion('class '.$classname.' is not exists!');
}
$reflecObj = new ReflectionClass($classname);
if(!$reflecObj->hasMethod($action)){
throw new Exception('method '.$action.' is not exists!');
}
$currentObj = new $classname();
echo "classname=$classname,action=$action,params=".json_encode($params)."<br/>";
call_user_func_array([$currentObj,$action],$params);
return;
?>然后創(chuàng)建一個(gè)簡(jiǎn)單的控制器 user.php,放到applicaiton/controllers/目錄下,具體內(nèi)容如下:
<?php
class User {
function __construct(){
}
public function index($name='')
{
echo 'hello,'.$name.',lucky,you are arrive here!';
}
}最后測(cè)試一個(gè)正確的控制器跳轉(zhuǎn)和錯(cuò)誤的控制器跳轉(zhuǎn)
首先測(cè)試一下正確的流程: http://192.168.1.99/user/index/xiaoming
輸出內(nèi)容:
classname=User,action=index,params={"2":"xiaoming"}
hello,xiaoming,lucky,you are arrive here!再測(cè)試一下不存在的控制器,http://192.168.1.99/account/index/xiaoming
Fatal error: Uncaught exception 'Exception' with message 'controller acount.php is not exists!' in /home/www/webroot/index.php:25Stack trace:#0 {main} thrown in
/home/www/webroot/index.php on line 25看完了這篇文章,相信你對(duì)“實(shí)現(xiàn)一個(gè)簡(jiǎn)單php框架的示例”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
網(wǎng)頁(yè)標(biāo)題:實(shí)現(xiàn)一個(gè)簡(jiǎn)單php框架的示例
URL鏈接:http://www.js-pz168.com/article12/gddjgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、網(wǎng)站排名、關(guān)鍵詞優(yōu)化、網(wǎng)站建設(shè)、、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)