???? PHP ???? ??? ?? ??? ?? ????????. PHP ???? ??? ?? ??? ?? ????? ?????? ?? ??? ???????.
???? ????? ??? ????
?? ??index.php
<?php define('WEBROOT', 'C:/Users/Administrator/Documents/NetBeansProjects/test'); require_once(WEBROOT.'/core/environment.php'); coreapp::run(); //
??? ?? ?? ?? Environment.php
<?php //根據(jù)類名來(lái)include文件 class loader { //找到對(duì)應(yīng)文件就include static function load($name) { $file = self::filepath($name); if ($file) { return include $file; } } static function filepath($name, $ext = '.php') { if (!$ext) { $ext = '.php'; } $file = str_replace('', '/', $name) . $ext; //類名轉(zhuǎn)路徑 $path .= WEBROOT . '/' . $file; if (file_exists($path)) { return $path; //找到就返回 } return null; } } spl_autoload_register('loader::load');
?? ???? ?? ?? ?? ??? coreapp::run() </? ????. ??? ???? code> /core/app.php ????? <code>run()
???? spl_autoload_register()
??? ???? ?? ??? ??? ?? ? ?? ??? ?????. ???? ???? ?????. < code>spl_autoload_register('loader::load'), ??? ??? ?? ?? ??? ??? ?????. coreapp::run()
對(duì)應(yīng) 根目錄/core/app.php 的 run()
方法,用到了spl_autoload_register()
函數(shù)實(shí)現(xiàn)自動(dòng)加載,當(dāng)調(diào)用某個(gè)類名的時(shí)候,會(huì)自動(dòng)執(zhí)行spl_autoload_register('loader::load')
,根據(jù)類名include對(duì)應(yīng)的類文件。
app.php入口文件執(zhí)行的方法開(kāi)始跑框架流程
<?php class coreapp { static function run() { $a = $_SERVER['REQUEST_URI']; $uri = rtrim(preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']), '/'); $params = explode('/', trim($uri, '/')); $count = count($params); if ($count >?1)?{ ??????$controller?=?$params[0]; ??????$method?=?$params[1]; ????}?elseif?($count?==?1)?{ ??????$controller?=?'index'; ??????$method?=?$params[0]; ????}?else?{ ????} ????$filename?=?WEBROOT?.?'/controller/'?.?$controller?.?'.php'; ????$controller?=?'controller'.$controller; ????try?{ ??????if?(!file_exists($filename))?{ ????????throw?new?Exception('controller?'?.?$controller?.?'?is?not?exists!'); ????????return; ??????} ??????include($filename); ??????if?(!class_exists($controller))?{ ????????throw?new?Exception('class?'?.?$controller?.?'?is?not?exists'); ????????return; ??????} ??????$obj?=?new?ReflectionClass($controller); ??????if?(!$obj->hasMethod($method))?{ ????????throw?new?Exception('method?'?.?$method?.?'?is?not?exists'); ????????return; ??????} ????}?catch?(Exception?$e)?{ ??????echo?$e;?//展示錯(cuò)誤結(jié)果 ??????return; ????} ????$newObj?=?new?$controller(); ????call_user_func_array(array($newObj,?$method),?$params); ??} }
根據(jù)請(qǐng)求uri去找對(duì)應(yīng)的controller, 用call_user_func_array()
的方式調(diào)用controller里的方法
根目錄/controller/test.php
<?php class?controllertest?{ ??public?function?write($controller,?$method)?{ ????//configtest::load('test'); ????modeltest::write($controller,?$method); ??} }
這里其實(shí)調(diào)用不一定要調(diào)用model里的test方法,可以調(diào)model目錄下的任意文件,在此之前可以去都讀一些config文件等等操作。
根目錄/model/test.php
<?php class?modeltest?{ ??public?function?write($model,?$method)?{ ????echo?'From?controller:'.$model.'?to?model:?'?.?$model?.?'?,method:?'?.?$method; ??} }
例如hostname/test/write 這個(gè)請(qǐng)求就會(huì)從入口文件進(jìn)來(lái),經(jīng)過(guò)coreapp::run
就會(huì)找到controller下對(duì)應(yīng)的的controllertest類,執(zhí)行write()
rrreee
?? URI? ?? ?? ????? ??call_user_func_array()
? ???? ?????? ???? ??????? ????/????/test.php
rrreee??? ??? ??? ? ??? ??? ??? ???? ??? ??? ????. ? ??? ?? ?? ??? ?? ? ????. ? ?? ??.
?? ????/model/test.php
?? ?? ??? ??/test/write ??? coreapp::run
??? ?? ???? ???? ?? ? ????. ??? ??? ?? write()
???? ?????? ??? ??? ??? ? ???? ??????? ?????. ? ???? ??? ??? ?? ???? ?? ?? ??? ?????. PHP ??? ????!
? ??? PHP? ??? ? ??? ?? ??? ?????.? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











PHP ??? ??? ?? ??? ????? php.ini? ???? ? ??? ???? ??? ??? ????? ????. 1. PHP ?? : Linux ? APT, Mac ? Homebrew ? Windows? ???? XAMPP ??; 2. php.ini ?? : ?? ???, ??? ?? ?? ???? ??? ?? ?????. 3. ? ?? ?? : Apache? mod_php? ???? nginx? php-fpm? ?????. 4. ?? ??? ???? ?? ????? ???? ?? : MySQLI, JSON, MBString ?? ?? ??.

tolearnpheffectical, startBysetTupaloCalserErverEnmentUsingToolslikexamppandacodeeditor -likevscode.1) installxamppforapache, mysql, andphp.2) useacodeeditorforsyntaxsupport.3)) 3) testimplephpfile.next, withpluclucincludechlucincluclucludechluclucled

?? ??????? ??? ?? ?? ??? ?? ????? ??? ???? ??? ????? ??? ??? ??? ??? ? ? ????. ??? ??? ??? ?? ???? ???? ?? ? ? ????. ??? ????? ???? ??? ??? ??, ?? ?? ?? ?? ? ?? ?? ??? ?????. ??? ?????? ???? ??? ??? ???? ? ? ??? ????? ??? ???? ????. ?? ?? ??? ???? ??, ??? ? ??? ?? ???? ?? ?? ? ?? ?? ???? ??? ????????. ??? ??? ?? ??? ??? ???? ?? ??? ?? ? ? ????. ??? ??? ???? ?? ??? ???? ?? ?? ?? ??? ??????.

PHP ??? ???? ??? ??? ??? ????? ????. ??? ????? ?? ???? ??? "?? ? ?"??? "?"? ???????. 1. ??? ? ??? ??? DocBlock (/*/)? ?? ?? ??? ???? ??? ? ?? ???? ??????. 2. JS ??? ???? ?? ???? ??? ?? ??? ??? ?????. 3. ??? ?? ?? ?? ??? ???? ????? ????? ???? ?? ????? ???? ? ??????. 4. Todo ? Fixme? ????? ???? ? ? ??? ??? ???? ?? ?? ? ??? ???????. ??? ???? ?? ??? ??? ?? ?? ?? ???? ???? ? ????.

toinstallphpquickly, usexampponwindowsorhomebrewonmacos.1. ??, downloadandinstallxAmpp, selectComponents, startApache ? placefilesinhtdocs.2

phpblockommentsearseforwritingmulti-lleexplanations, temporlyblingcode, and generatingdocumentation.theyshouldnotbenesteTeRleftUnclosed.blockmentShelPindOcumentingFunctionSwitHphPDoc, whatlsoompsTormuseforauto-CompletionAnderRorChe

?? ??? ???? ??? ??? ???? ????? ?? "?? ? ?"? ??? "?"? ???? ????. 1. ??? ?? ?? ?? ??? ?? ??? ?? ??? ??? ???????. 2. ??? ??? ?? ?? ??? ???? ?? ?? ????? ???? ????? ?????. 3. ????? ??? ???? ??? ???? ????, ???? ???, ??? ?? ?? ???? ?????. 4. ??? ?? ? ? ??? ??? ???? ?? ??? ??? ??? ?? ??? ?? ?? ??? ??????.

PHP ?? ???? ? ?? ???? ??? ????. 1. // ?? #? ???? ? ?? ??? ???? // ???? ?? ????. 2. ?? /.../ ?? ?? ?? ??? ????? ?? ? ?? ??? ?? ? ? ????. 3. ?? ?? ?? / if () {} /? ?? ?? ??? ????? ??? ?? ?? ?? ??? ???? ????? ???? ??? ?? ???? ???? ??? ? ??? ??????.
