A super simple php framework
Jul 29, 2016 am 09:15 AMI recently wrote a php framework myself, the github address is as follows:
blakeFez-PHP-Framework
This framework has relatively few functions and is more suitable for small personal websites.
The directory structure of the framework is as follows:
<code>/command <span>//該目錄用于存放cli模式下的command類</span> /controller <span>//該目錄用于存放cgi模式下的controller類</span> /frame <span>//該目錄用于存放框架的核心代碼</span> BlakeFez.php <span>//這是框架的核心文件</span> Command.php <span>//command的基類,所有的command類都要繼承該類</span> CommonMysql.php <span>//實(shí)現(xiàn)的一個(gè)mysql類</span> CommonRequest.php <span>//實(shí)現(xiàn)的一個(gè)獲取url請(qǐng)求類,最好使用</span><span>//CommonRequest::getRequest('option')來代替</span><span>//$_GET['option']和$_POST['option']</span> Controller.php <span>//controller類的基類,所有的controller類都要</span><span>//繼承該類</span> Model.php <span>//model類的基類,所有的model都要繼承該類</span> /model <span>//該目錄用于存放model類</span> /service <span>//該目錄用于存放公用的service類</span> /<span>static</span><span>//該目錄用于存放js、css、圖片等</span> /view <span>//該目錄用于存放前端模板文件</span></code>
The framework supports both CGI and CLI modes.
In CGI mode, the usage method is as follows:
①、Routing method
For example, there is such a url: http://host/index.php?c=index&a=welcome
Then the welcome method of the IndexController class in the /controller directory will actually be requested.
②、Front-end rendering
In the controller, use:
<code>$<span>this</span>-><span>out</span>[<span>'title'</span>] = <span>'welcome to china'</span>;</code>
will output the variable title to the front end. In the front-end template file, you can use this variable like this:
<code><span><<span>title</span>></span><span><span><?php</span><span>echo</span><span>$title</span>;<span>?></span></span><span></<span>title</span>></span></code>
The naming method of the front-end file is like this:
For example, the front-end file corresponding to the welcome method of the IndexController class is:
/view/index/welcome.php
If it is an asynchronous request and does not require front-end rendering, you can write it like this in the controller:
<code><span>$this</span><span>-></span>outType <span>=</span><span>'json'</span>;</code>
In CGI mode, the usage method is as follows:
php SRC_PATH/index.php -c index -a index
This line of naming will execute the index method of the IndexCommand class in the command directory.
Copyright Statement: This article is an original article by the blogger. Please indicate the source when reprinting.
The above introduces a super simple PHP framework, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

TosettherighttimezoneinPHP,usedate_default_timezone_set()functionatthestartofyourscriptwithavalididentifiersuchas'America/New_York'.1.Usedate_default_timezone_set()beforeanydate/timefunctions.2.Alternatively,configurethephp.inifilebysettingdate.timez

TovalidateuserinputinPHP,usebuilt-invalidationfunctionslikefilter_var()andfilter_input(),applyregularexpressionsforcustomformatssuchasusernamesorphonenumbers,checkdatatypesfornumericvalueslikeageorprice,setlengthlimitsandtrimwhitespacetopreventlayout

ThePhpfunctionSerialize () andunserialize () AreusedtoconvertcomplexdaTastructdestoresintostoraSandaBackagain.1.Serialize () c OnvertsdatalikecarraysorobjectsraystringcontainingTypeandstructureinformation.2.unserialize () Reconstruct theoriginalatataprom

You can embed PHP code into HTML files, but make sure that the file has an extension of .php so that the server can parse it correctly. Use standard tags to wrap PHP code, insert dynamic content anywhere in HTML. In addition, you can switch PHP and HTML multiple times in the same file to realize dynamic functions such as conditional rendering. Be sure to pay attention to the server configuration and syntax correctness to avoid problems caused by short labels, quotation mark errors or omitted end labels.

The key to writing clean and easy-to-maintain PHP code lies in clear naming, following standards, reasonable structure, making good use of comments and testability. 1. Use clear variables, functions and class names, such as $userData and calculateTotalPrice(); 2. Follow the PSR-12 standard unified code style; 3. Split the code structure according to responsibilities, and organize it using MVC or Laravel-style catalogs; 4. Avoid noodles-style code and split the logic into small functions with a single responsibility; 5. Add comments at key points and write interface documents to clarify parameters, return values ??and exceptions; 6. Improve testability, adopt dependency injection, reduce global state and static methods. These practices improve code quality, collaboration efficiency and post-maintenance ease.

Yes,youcanrunSQLqueriesusingPHP,andtheprocessinvolveschoosingadatabaseextension,connectingtothedatabase,executingqueriessafely,andclosingconnectionswhendone.Todothis,firstchoosebetweenMySQLiorPDO,withPDObeingmoreflexibleduetosupportingmultipledatabas
