> php教程 > php手册 > 본문

我用了13行代碼開發出来的PHP框架

WBOY
풀어 주다: 2016-07-09 09:10:13
원래의
1540명이 탐색했습니다.

我只用13行代碼開發的PHP框架,如果您對框架不理解,不知道框架究竟幫您做了什麽事,可以下載此框架看一下,

另外如果您想開發自己的框架也可以由這個框架的思路進行擴展.

源碼下載地址:http://download.csdn.net/detail/sibang/6197315

代碼:

<span style="color: #008080;"> 1</span> <span style="color: #000000;">PHP
</span><span style="color: #008080;"> 2</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;"> 3</span> <span style="color: #008000;">    PHP極簡框架
</span><span style="color: #008080;"> 4</span> <span style="color: #008000;">    交流:
</span><span style="color: #008080;"> 5</span> <span style="color: #008000;">        QQ群: 223494678
</span><span style="color: #008080;"> 6</span> <span style="color: #008000;">        http://7di.net
</span><span style="color: #008080;"> 7</span> <span style="color: #008000;">    用法
</span><span style="color: #008080;"> 8</span> <span style="color: #008000;">        http://URL
</span><span style="color: #008080;"> 9</span> <span style="color: #008000;">        http://URL/hello
</span><span style="color: #008080;">10</span> <span style="color: #008000;">        http://URL/seven.php?w=hello
</span><span style="color: #008080;">11</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*/</span>
<span style="color: #008080;">12</span> 
<span style="color: #008080;">13</span> <span style="color: #008080;">Header</span>('Content-type: text/html; charset=UTF-8'<span style="color: #000000;">);
</span><span style="color: #008080;">14</span> <span style="color: #800080;">$w</span>=<span style="color: #0000ff;">isSet</span>(<span style="color: #800080;">$_REQUEST</span>['w']) ? <span style="color: #008080;">AddsLashes</span>(<span style="color: #800080;">$_REQUEST</span>['w']) : ''<span style="color: #000000;">;
</span><span style="color: #008080;">15</span> <span style="color: #800080;">$w</span>=(<span style="color: #008080;">Trim</span>(<span style="color: #800080;">$w</span>)=='') ? 'index' : <span style="color: #800080;">$w</span><span style="color: #000000;">;
</span><span style="color: #008080;">16</span> 
<span style="color: #008080;">17</span> <span style="color: #0000ff;">IF</span>(!<span style="color: #008080;">is_callable</span>(<span style="color: #800080;">$w</span><span style="color: #000000;">)) {
</span><span style="color: #008080;">18</span>     <span style="color: #0000ff;">Exit</span>('Error:'.<span style="color: #ff00ff;">__LINE__</span>.',參數錯誤!'<span style="color: #000000;">);
</span><span style="color: #008080;">19</span> <span style="color: #000000;">}
</span><span style="color: #008080;">20</span> <span style="color: #800080;">$w</span><span style="color: #000000;">();
</span><span style="color: #008080;">21</span> 
<span style="color: #008080;">22</span> <span style="color: #0000ff;">Function</span><span style="color: #000000;"> hello(){
</span><span style="color: #008080;">23</span>     <span style="color: #0000ff;">Echo</span> 'Hello World!'<span style="color: #000000;">;
</span><span style="color: #008080;">24</span> <span style="color: #000000;">}
</span><span style="color: #008080;">25</span> 
<span style="color: #008080;">26</span> <span style="color: #0000ff;">Function</span><span style="color: #000000;"> index(){
</span><span style="color: #008080;">27</span>     <span style="color: #0000ff;">Echo</span> '此框架由Seven編寫,來自QQ群:223494678'<span style="color: #000000;">;
</span><span style="color: #008080;">28</span> }
로그인 후 복사

.htaccess的內容

 

下邊是註釋:

Header('Content-type: text/html; charset=UTF-8');
//定義編碼

$w=isSet($_REQUEST['w']) ? AddsLashes($_REQUEST['w']) : '';
//獲取參數w的值,w來自于rewrite規則文件.htaccess

$w=(Trim($w)=='') ? 'index' : $w;
//如果參數w的值為空,則訪問默認的index方法

IF(!is_callable($w)) {
	//如果$w所屬的function不存在

	Exit('Error:'.__LINE__.',參數錯誤!');
	//拋出錯誤
}
$w();
//調用$w名稱對應的function,例如:http://URL/hello會調用hello()這個function

//自定義方法(可自由擴展)
Function hello(){
	Echo 'Hello World!';
}

Function index(){
	Echo '此框架由Seven編寫,來自QQ群:223494678';
}
로그인 후 복사

 

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿