boxunsoft / php-framework
PHP MVC Framework
v4.0.1
2020-06-24 10:22 UTC
Requires
- php: >=7.2
- boxunphp/config: ^2.0
- boxunphp/exception: ^2.0
- boxunphp/logger: ^2.0
- boxunphp/request: ^2.0
- nikic/fast-route: ^1.3
- psr/http-message: 1.0.1
- symfony/console: ^5.0
- symfony/http-foundation: ^5.1
README
一个简单的PHP MVC框架
Usage
Install
In composer.json
... "require": { "boxunsoft/php-framework": "^4.0" }, "autoload": { "psr-4": { "Bx\\": "src/" } } ...
应用目录
env // 环境配置
|-develop
|- app.php
|-test
|- app.php
|-release
config // 系统配置
|- router // 路由
|- appname.php
public // 入口
|- appname
|- index.php
src
|- App // 多应用
|- AppName // 应用一
|- Controller // 应用控制器
|- Index.php
|- View // 应用视图,可自行选择模板引擎
|- Index.phtml
|- Model // 存放模型
|- Library // 存放自定义类库
public/appname/index.php
目录和文件名必须小写
use Alf\Kernel; $rootPath = (dirname(__DIR__), 3); require $rootPath . '/vendor/autoload.php'; $Kernel = Kernel::getInstance(); $app->Kernel($rootPath, 'AppName');
App/AppName/Controller/Index.php
namespace Bx\App\AppName\Controller; use Alf\Controller; class Index extends Controller { public function main() { $response = [ 'name' => 'index', 'message' => 'Index::main()' ]; $this->response()->success($response); } }
安全建议
// 只允许同域名iframe嵌套
header('X-Frame-Options: SAMEORIGIN');
// 禁止浏览器用MIME-sniffing解析资源类型
header('X-Content-Type-Options: nosniff');
// 启用XSS保护
header('X-XSS-Protection: 1; mode=block');
引用
- symfony/http-foundation
- nikic/fast-route
- symfony/console