nkey / caribu-mvc

小巧的 (M)VC 模式框架

v1.0 2017-04-22 05:33 UTC

This package is auto-updated.

Last update: 2024-09-29 04:25:38 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Dependency Status

caribu-mvc

基于注解的 MVC 框架

目前仅提供一个简单的示例,展示 Caribu MVC 可以做什么。

composer.json

{
  "require" : {
    "nkey/caribu-mvc" : "dev-master",
    "nkey/phpgenerics" : "dev-master",
    "psr/log" : "1.0.0"
  }
}

public/index.php

<?php
require dirname(__FILE__) . '/../vendor/autoload.php';

use \Nkey\Caribu\Mvc\Controller\AbstractController;
use \Nkey\Caribu\Mvc\Controller\Request;
use \Nkey\Caribu\Mvc\Application;
use \Nkey\Caribu\Mvc\View\AbstractView;

use \Generics\Logger\ExtendedLogger;

/**
 * A simple test controller
 *
 * @author Maik Greubel <greubel@nkey.de>
 *
 *         This file is part of Caribu MVC package
 */
class IndexController extends AbstractController
{

    /**
     * @webMethod
     *
     * @title Hey there page
     */
    public function index()
    {
        echo "Hey, there!\n\n";
    }

    /**
     * @responseType text/plain
     *
     * @param \Nkey\Caribu\Mvc\Controller\Request $request
     */
    public function paramTest(Request $request)
    {
        foreach ($request->getParams() as $param => $value) {
            printf("%s => %s\n", $param, $value);
        }
    }
}

// Preparing
Application::getInstance()->registerController('IndexController')
    ->setLogger(new ExtendedLogger());

// Serving
Application::getInstance()->serve();

然后在浏览器窗口中打开 http://host/,查看 index() 网络方法的结果。地址 http://host/index,以及 http://host/index/index 提供相同的功能。

访问 http://host/index/paramTest/param1/Hello/param2/Caribu 或使用相同的地址 http://host/index/paramTest?param1=Hello&param2=Caribu 来获取相同的输出。

文档将很快在 Wiki 中更新。