介绍
介绍
TFWEB是一款基于PHP语言开发的框架,用于快速开发web应用!
结构
目录结构
基本目录结构
css:样式表文件目录
fonts:字体库文件目录
images:图片文件目录
js:脚本文件目录
WEB-INF:项目文件目录

项目目录结构
Config:配置对象目录
Controller:控制器对象目录
Model:模型对象目录
Resource:资源文件目录
View:视图模板目录
Autoload.inc.php:自动加载

配置
基本结构

配置文件
xml
Config/config/config.xml
<?xml version="1.0" encoding="utf-8" ?> <TFPHP xmlns="http://tongfu.net/tfphp/1.0.0"> <system> <charset>UTF-8</charset> <serverRootUri>/tfphp/</serverRootUri> </system> <TFDO> <default> <driver>MySQL</driver> <host>tfmysql</host> <port>3306</port> <user>root</user> <pass>abcdef</pass> <db>tfphp</db> <charset>utf8mb4</charset> </default> </TFDO> <TFRedis> <default> <host>tfredis</host> <port>6379</port> <pass>tongfu.net</pass> <db>tfphp</db> </default> </TFRedis> <TFElasticsearch> <default> <host>tfelasticsearch</host> <port>9200</port> <user>elastic</user> <pass>abcdef</pass> <db>tfphp</db> </default> </TFElasticsearch> </TFPHP>
基础对象
API
Config/base/api/myController.inc.php
<?php
namespace TFProject\Config\base\api;
use TFProject\Config\auth\api\authorization;
use TFPHP\Controller\API\TFController;
class myController extends TFController{
protected function prepare(){
$this->authorization = new authorization($this->tfphp);
$this->authorization->start();
}
}页面
Config/base/page/myController.inc.php
<?php
namespace TFProject\Config\base\page;
use TFProject\Config\auth\page\authorization;
use TFPHP\Controller\Page\TFController;
class myController extends TFController{
protected function prepare(){
$this->authorization = new authorization($this->tfphp);
$this->authorization->start();
}
}认证对象
API
Config/auth/api/myController.inc.php
<?php
namespace TFProject\Config\auth\api;
use TFPHP\Controller\Authorization\TFAuthorization;
class authorization extends TFAuthorization{
protected function makeAuthorizeRules(){
$this->addAuthorizeRule("public", [
"\/api\/.*",
]);
}
protected function authorizedProcess(string $ruleName){
}
protected function unauthorizedProcess(){
$this->tfphp->getResponse()->responseStatus(404)->done();
}
}页面
Config/auth/page/myController.inc.php
<?php
namespace TFProject\Config\auth\page;
use TFPHP\Controller\Authorization\TFAuthorization;
class authorization extends TFAuthorization{
protected function makeAuthorizeRules(){
$this->addAuthorizeRule("public", [
"\/",
]);
}
protected function authorizedProcess(string $ruleName){
}
protected function unauthorizedProcess(){
$this->tfphp->getResponse()->responseStatus(404)->done();
}
}控制器
API
Controller/api/index.inc.php
<?php
use TFProject\Config\base\api\myController;
class APIController extends myController{
protected function action_get(){
$this->tfphp->getResponse()->responseJSON_CM(200, 0, "OK");
}
}页面
Controller/index.inc.php
<?php
use TFProject\Config\base\page\myController;
class PageController extends myController {
}视图
模板
View/Template/index.html
<!DOCTYPE html> <html> <head> <% $tfres->getHead()->getHtml() %> <% $tfhtml->getHeadHtml() %> </head> <body> <h3>Hello TFPHP</h3> </body> </html> <% $tfhtml->getStartHtml() %>
脚本
CSS
js/pages/index.css
/* Define styles for web page */
JS
js/pages/index.js
var tfpage = {
start : function() {
/* Do something after web page loaded */
}
}效果
API
页面