2017 © Pedro Peláez
 

library rka-slim-controller

Dynamically instantiated controller classes for Slim Framework

image

akrabat/rka-slim-controller

Dynamically instantiated controller classes for Slim Framework

  • Wednesday, January 7, 2015
  • by akrabat
  • Repository
  • 6 Watchers
  • 50 Stars
  • 16,632 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 4 Forks
  • 1 Open issues
  • 8 Versions
  • 6 % Grown

The README.md

RKA Slim Controller

An extension to [Slim Framework][1] that allows you use to dynamically instantiated controllers with action methods wherever you would use a closure when routing., (*1)

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

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:, (*3)

e.g., (*4)

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

You can also register the controller with Slim's DI container:, (*5)

$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., (*6)

Hence, a typical controller may look like:, (*7)

<?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., (*8)

The Versions

07/01 2015

dev-master

9999999-dev http://github.com/akrabat/rka-slim-controller

Dynamically instantiated controller classes for Slim Framework

  Sources   Download

BSD-3-Clause

The Requires

 

slim controller

07/01 2015

2.0.1

2.0.1.0 http://github.com/akrabat/rka-slim-controller

Dynamically instantiated controller classes for Slim Framework

  Sources   Download

BSD-3-Clause

The Requires

 

slim controller

07/01 2015

2.0

2.0.0.0 http://github.com/akrabat/rka-slim-controller

Dynamically instantiated controller classes for Slim Framework

  Sources   Download

BSD-3-Clause

The Requires

 

slim controller

06/01 2015

1.0.4

1.0.4.0 http://github.com/akrabat/rka-slim-controller

Dynamically instantiated controller classes for Slim Framework

  Sources   Download

BSD-3-Clause

The Requires

 

slim controller

15/12 2014

1.0.3

1.0.3.0 http://github.com/akrabat/rka-slim-controller

Dynamically instantiated controller classes for Slim Framework

  Sources   Download

BSD-3-Clause

The Requires

 

slim controller

15/12 2014

1.0.2

1.0.2.0 http://github.com/akrabat/rka-slim-controller

Dynamically instantiated controller classes for Slim Framework

  Sources   Download

BSD-3-Clause

The Requires

 

slim controller

15/12 2014

1.0.1

1.0.1.0 http://github.com/akrabat/rka-slim-controller

Dynamically instantiated controller classes for Slim Framework

  Sources   Download

BSD-3-Clause

The Requires

 

slim controller

15/12 2014

1.0.0

1.0.0.0 http://github.com/akrabat/rka-slim-controller

Dynamically instantiated controller classes for Slim Framework

  Sources   Download

BSD-3-Clause

The Requires

 

slim controller