Home  >  Article  >  Backend Development  >  A super simple php framework

A super simple php framework

WBOY
WBOYOriginal
2016-07-29 09:15:523001browse

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><<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.

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