drmvc/framework

简单灵活的PHP7 MVC框架

3.0.0 2018-04-19 12:11 UTC

README

Latest Stable Version Build Status Total Downloads License PHP 7 ready Code Climate Scrutinizer CQ

DrMVC\Framework

这是一个结合了创建完整Web应用所需的一些模块的框架。

composer require drmvc/framework

如何使用

更多示例请查看 这里

public_html文件夹中的index.php示例

<?php
require_once __DIR__ . '/../vendor/autoload.php';

$config = new \DrMVC\Config();
$config->load(__DIR__ . '/../app/database.php', 'database');

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

$app = new \DrMVC\App($config);
$app
    ->get('/', \MyApp\Controllers\Index::class . ':default') //-> public function action_default()
    ->get('/zzz', \MyApp\Controllers\Index::class) //-> public function action_index()
    ->get('/zzz/<action>', \MyApp\Controllers\Index::class)
    ->get('/aaa', function(Request $request, Response $response, $args) {
        print_r($args);
    });

echo $app->run();

app/Controllers文件夹中的Index控制器示例

<?php

namespace MyApp\Controllers;

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

class Index
{
    public function action_index(Request $request, Response $response, $args)
    {
        $out = [
            'dummy',
            'array'
        ];

        $json = json_encode($out);
        header('Content-Type: application/json');
        $response->getBody()->write($json);
    }

    public function action_defaultRequest $request, Response $response, $args)
    {
        $out = [
            'test1',
            'test2'
        ];

        $json = json_encode($out);
        header('Content-Type: application/json');
        $response->getBody()->write($json);
    }
}

获取帮助的地方

如果你发现了bug,请在GitHub Issues页面报告。

关于PHP单元测试

首先需要通过composer update安装所有开发依赖,然后可以从源目录通过./vendor/bin/phpunit命令手动运行测试。

链接

  • DrMVC框架
  • Slim - 这是一个PHP微框架,我非常喜欢其实现的PSR-4概念。
  • SimpleMVC - 这是一个非常令人兴奋的项目,在作者将其重命名为Nova之前
  • Phalcon - 简洁明了的应用程序代码