akrabat/rka-slim-controller 问题修复 & 功能扩展

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

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

akrabat/rka-slim-controller

最新稳定版本:2.0.1

Composer 安装命令:

composer require akrabat/rka-slim-controller

包简介

Dynamically instantiated controller classes for Slim Framework

README 文档

README

An extension to Slim Framework that allows you use to dynamically instantiated controllers with action methods wherever you would use a closure when routing.

The controller can optionally be loaded from Slim's DI container, allowing you to inject dependencies as required.

Installation

composer require akrabat/rka-slim-controller

Usage

Use the string format {controller class name}:{action method name} wherever you would usually use a closure:

e.g.

$app = new \RKA\Slim();
$app->get('/hello:name', 'App\IndexController:home');

You can also register the controller with Slim's DI container:

$app = new \RKA\Slim();

$app->container->singleton('App\IndexController', function ($container) {
    // Retrieve any required dependencies from the container and
    // inject into the constructor of the controller

    return new \App\IndexController();
});

$app->get('/', 'App\IndexController:index');

Controller class methods

RKA Slim Controller will call the controller's setApp(), setRequest() and setResponse() methods if they exist and populate appropriately. It will then call the controller's `init()`` method.

Hence, a typical controller may look like:

<?php
namespace App;

class IndexController
{
    // Optional properties
    protected $app;
    protected $request;
    protected $response;

    public function index()
    {
        echo "This is the home page";
    }

    public function hello($name)
    {
        echo "Hello, $name";
    }

    // Optional setters
    public function setApp($app)
    {
        $this->app = $app;
    }

    public function setRequest($request)
    {
        $this->request = $request;
    }

    public function setResponse($response)
    {
        $this->response = $response;
    }

    // Init
    public function init()
    {
        // do things now that app, request and response are set.
    }
}

Example project

Look at slim-di.

统计信息

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

GitHub 信息

  • Stars: 48
  • Watchers: 6
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-12-15