search
HomeBackend DevelopmentPHP TutorialA super simple php framework

I 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>//实现的一个mysql类</span>
    CommonRequest.php <span>//实现的一个获取url请求类,最好使用</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>title</span>><span><span><?php </span><span>echo</span><span>$title</span>;<span>?></span></span><span><span>title</span>></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.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between unset() and session_destroy()?What is the difference between unset() and session_destroy()?May 04, 2025 am 12:19 AM

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

What is sticky sessions (session affinity) in the context of load balancing?What is sticky sessions (session affinity) in the context of load balancing?May 04, 2025 am 12:16 AM

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

What are the different session save handlers available in PHP?What are the different session save handlers available in PHP?May 04, 2025 am 12:14 AM

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

What is a session in PHP, and why are they used?What is a session in PHP, and why are they used?May 04, 2025 am 12:12 AM

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

Explain the lifecycle of a PHP session.Explain the lifecycle of a PHP session.May 04, 2025 am 12:04 AM

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

What is the difference between absolute and idle session timeouts?What is the difference between absolute and idle session timeouts?May 03, 2025 am 12:21 AM

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

What steps would you take if sessions aren't working on your server?What steps would you take if sessions aren't working on your server?May 03, 2025 am 12:19 AM

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

What is the significance of the session_start() function?What is the significance of the session_start() function?May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool