mrblue/mvc 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mrblue/mvc

最新稳定版本:1.3.1

Composer 安装命令:

composer require mrblue/mvc

包简介

Simple and ultra-fast MVC

关键字:

README 文档

README

composer require mrblue/mvc

File ./Controller/MainController.php

<?php
namespace Controller;

class MainController extends \mrblue\mvc\AbstractController
{
    function getUser ()
    {
        return [ // this array will be rendered as json
            'status' => 'ok'
            'user_id' => $this->Mvc->getROuteMatch()->getParams()['user_id']
        ];
    }

    function geHtmlPage ()
    {
        return [
            'user_id' => $this->Mvc->getROuteMatch()->getParams()['user_id']
        ];
    }

    function getTxtContent()
    {
        return file_get_contents( __DIR__ . '/contents/plaintext.txt' );
    }

    function dowloadFile()
    {
        $file_target = __DIR__ . '/contents/open_data.csv';

        header('Content-Type: text/csv');
        header('Content-Disposition: attachment; filename="export.csv"');
        header('Content-Length: '.filesize($file_target));
        return fopen( $file_target );
    }
}

File ./view/html_page.phtml

<?php

/**
 * @var \mrblue\mvc\RenderView $this
 */

 $data = $this->getData();

?>
<h1>User id is <?php echo $data ['user_id'] ?></h1>

File ./index.php

<?php
include 'vendor/autoload.php';

$Mvc = new Mvc([
    'router' => [
        'routes' => [
            'apiv1' => [
                'type' => \mrblue\mvc\Route::TYPE_SEGMENT,
                'equal_to' => '/api/v1/:user_id',
                'controller' => Controller\MainController::class,
                'constraints' => [
                    'user_id' => '\d+'
                ]
                'may_terminate' => false,
                'childs' => [
                    'json_example' => [
                        'type' => \mrblue\mvc\Route::TYPE_LITERAL,
                        'equal_to' => '/me',
                        'defaults' => [
                            'action' => 'getUser'
                        ],
                        'constraints' => [
                            'user_id' => '\d+'
                        ]
                    ],
                    'html_render_example' => [
                        'type' => \mrblue\mvc\Route::TYPE_LITERAL,
                        'equal_to' => '/html_page',
                        'view_template' => __DIR__ . '/view/html_page.phtml',
                        'defaults' => [
                            'action' => 'geHtmlPage'
                        ]
                    ],
                    'txt_print_example' => [
                        'type' => \mrblue\mvc\Route::TYPE_LITERAL,
                        'equal_to' => '/txt_content',
                        'defaults' => [
                            'action' => 'getTxtContent'
                        ]
                    ],
                    'download_stream_example' => [
                        'type' => \mrblue\mvc\Route::TYPE_LITERAL,
                        'equal_to' => '/download',
                        'defaults' => [
                            'action' => 'download'
                        ]
                    ],
                ]
            ]
        ]
    ]
]);

$Mvc->run();

统计信息

  • 总下载量: 4.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-08