Download the PHP package talesoft/tale-controller without Composer
On this page you can find all versions of the php package talesoft/tale-controller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download talesoft/tale-controller
More information about talesoft/tale-controller
Files in talesoft/tale-controller
Package tale-controller
Short Description A controller middleware for talesoft/tale-app
License MIT
Homepage http://docs.talesoft.io/tale-framework/tale/controller
Informations about the package tale-controller
Tale Controller
A Tale Framework Component
What is Tale Controller?
A middleware for talesoft/tale-app
that allows easy instanciation and handling of controllers.
You can either use single, static controllers or use a dispatcher that automatically handles everything.
Installation
Install via Composer
Usage
Single usage
A single controller can make up a whole website. This is really useful for small websites with 5-10 sub-pages. No configuration needed.
Using the Dispatcher
When apps get larger, you want to split functionality into single modules. With the Dispatcher you can control an automatic controller dispatching mechanism.
Imagine the following controller structure:
This is a common case that the dispatcher can handle with a low configuration profile.
Now you could call the editAction
of the Admin\IndexController
by requesting
index.php?module=admin&action=edit
Notice that all values are completely optional.
ServerRequestInterface attributes
The following attributes are handled by the dispatcher:
module
(Default: null
)
Tells the dispatcher which namespace to find controllers in.
The controller.nameSpace
option will be prepended in any case.
controller
(Default: index
)
Tells the dispatcher, which controller to load.
my-blog
will be parsed to MyBlogController
The following attributes are handled by the controllers:
action
(Default: index
)
Tells the controller which action to call.
edit-user
will be parsed to editUserAction
If there's an getEditUserAction
-method, that one will only listen to GET
-requests
The same goes for POST
-requests with postEditUserAction
.
Not prefixing will handle all request methods.
id
(Default: null)
Specifies the first parameter given to the action.
Allowed values are numerical values and canonical strings (some-user-name
)
format
(Default: html)
Specifies the format the result should appear in.
This mostly equals the file extension of the called URI (/some-file.xml
will yield format xml
)
This format is to be used by some kind of output formatter/renderer.
Handle 404-errors
What if there's no fitting controller/it doesn't extend the correct class/the input is malformed etc.
That's all checked by tale-controller. Upon any kind of failure, control will be passed on to the next middleware.
Handling 404 is as simple as adding an "end"-middleware that results in said 404-error
Shorten things up
This module is specially designed to work with the Tale\Router
.
You can use it stand-alone, but it will require extra-work (but is still really cool!)
Here's an example of how it could look like by installing talesoft/tale-router
via composer
env.json
Configuration options
All configuration options.
Using multiple dispatchers
Using multiple dispatchers is as easy as extending the dispatcher. You can set an option namespace to load different configuration values.
All versions of tale-controller with dependencies
psr/http-message Version ~1.0
talesoft/tale-app Version ~0.1
talesoft/tale-http-runtime Version ~0.1
talesoft/tale-inflector Version ~0.1
talesoft/tale-loader Version ~0.1