Download the PHP package dbeurive/slim-controller without Composer
On this page you can find all versions of the php package dbeurive/slim-controller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dbeurive/slim-controller
More information about dbeurive/slim-controller
Files in dbeurive/slim-controller
Package slim-controller
Short Description This package contains a controller manager for the SLIM framework
License Creative Commons Attribution 4.0 International Public License
Informations about the package slim-controller
- Introduction
- Synopsis
- Define the controllers
- Create the index that lists all controllers
- Implement the Slim application
Introduction
This package allows the use of "controllers" with the Slim framework.
Synopsis
Define the controllers
$ tree /path
/path
└── to
└── controllers
├── ProfileController.php
└── UserController.php
Please note the suffix used to create the controllers' file names: "
Controller.php
". This suffix can be changed.Please note the names of the methods that implement the controllers' actions ("actionPostSet" and "actionGetGet"). Actions' names start with the prefix "
action
", followed by the name of the expected HTTP method (see the Slim's documentation).Please note the annotation "
@uri-params {id}
" (for the method "actionGetGet()
"). This means that the URI associated with this action is "/profile/get/{id}
".Please have a look to the controller UserController.php.
Create the index that lists all controllers
The index "
/app/data/index.json
" contains data about the controllers. Please click here to see the content of this file.Please click here to see the script slim-controller.php.
You can dump the content of the index in a human readable way:
$ php slim-controller.php dump --host http://www.slim-controller.localhost /app/data/index.json
POST http://www.slim-controller.localhost/profile/set
/path/to/controllers/ProfileController.php
\dbeurive\Slim\Test\controller0\ProfileController::actionPostSet
GET http://www.slim-controller.localhost/profile/get/{id}
/path/to/controllers/ProfileController.php
\dbeurive\Slim\Test\controller0\ProfileController::actionGetGet
POST http://www.slim-controller.localhost/user/login
/path/to/controllers/UserController.php
\dbeurive\Slim\Test\controller0\UserController::actionPostLogin
GET http://www.slim-controller.localhost/user/get/{id}
/path/to/controllers/UserController.php
\dbeurive\Slim\Test\controller0\UserController::actionGetGet
Implement the Slim application
Please note that, within this example, only the actions within the expected controller (depending on the URL) will be declared. For example, let's says that the URL is:
http://www.slim-controller.localhost/profile/get/10
. The expected controller is "ProfileController".This behaviour can be modified. Indeed, it is possible to configure the controller manager so that it will systematically register all routes (from all controllers). To do that, we should have written:
ControllerManager::start($app, '/app/data/index.json', true);
Please, click here to see the real example.
All versions of slim-controller with dependencies
symfony/console Version *
jan-swiecki/simple-annotations Version *
dbeurive/util Version *