Download the PHP package codermarcel/simple-controller without Composer
On this page you can find all versions of the php package codermarcel/simple-controller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codermarcel/simple-controller
More information about codermarcel/simple-controller
Files in codermarcel/simple-controller
Package simple-controller
Short Description Convenient and simple silex controller using reflection
License MIT
Informations about the package simple-controller
SimpleController
SimpleController is a convenient reflection based controller for the [php micro-framework silex] (http://silex.sensiolabs.org/) SimpleController makes it easy for you to use controllers in your silex applications and matches your controller methods to routes automatically
Installation
Run the following command:
Setup
Method - 1
Extending the SimpleController
Mount the route
Method - 2
Using a raw class
If you don't want to extend the SimpleController class, then you can use a raw class as well.
Mount the route
Note use the full namespace name for your controller class
Usage
HTTP methods
The method names should begin with the HTTP verb they respond to followed by the route name. The following methods are available :
- get
- post
- put
- delete
- patch
- options
- match
below are some examples
Organizing Controllers
When your application starts to define too many controllers, you might want to group them logically:
mount() prefixes all routes with the given prefix and merges them into the main Application. So, / will map to the main home page, /blog/ to the blog home page, and /forum/ to the forum home page.
For more information on Organizing Controllers, please take a look at the offical [silex documentation] (http://silex.sensiolabs.org/doc/organizing_controllers.html#organizing-controllers)
Example 1
Example 2
Route variables
You can define variable parts in a route like this:
Note default route values are currently not supported but might be added in a later version.
Request and Application injection
You can also ask for the current Request and Application objects like this:
Note silex does the injection based on the type hinting and not on the variable name!
Named routes
You can bind a route name to your routes by using the $bind parameter in your routes.
For more information on named route and the UrlGeneratorServiceProvider please take a look at the [offical silex documentation] (http://silex.sensiolabs.org/doc/providers/url_generator.html#urlgeneratorserviceprovider)
Middleware
Silex allows you to run code, that changes the default Silex behavior, at different stages during the handling of a request through middlewares: […] Route middlewares are triggered when their associated route is matched.
For more information about middlewares, please take a look at the offical [silex documentation] (http://silex.sensiolabs.org/doc/middlewares.html#middlewares)
Note You can typehint the Request, Response or Application object and silex will inject them for you.
Credits
SimpleController was inspired by https://gist.github.com/igorw/4524636 And http://laravel.com/docs/5.1/controllers#implicit-controllers