Download the PHP package yaf/extras without Composer
On this page you can find all versions of the php package yaf/extras. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package extras
Short Description Extras package for the Yet Another Framework
License MIT
Homepage http://github.com/rhyzx/php-yaf-extras
Informations about the package extras
Yaf Extras
Installation
Install via Composer
Class: RESTfulRouter
RESTful router, provide a quick way to register RewriteRoute with HTTP method adaptation(RESTful).
$router = new RESTfulRouter
Create a router.
$router->on($method, $url, $controller, $action)
- $method String: HTTP method name, support wildcard
*to match all methods. - $url String
- $controller String: controller class name
- $action String: method name of controller
Tips. you can register multi methods in single on(), use space to separate methods, eg. $router->on('get post', 'user/:id', 'user', 'show')
Example
Strict Mode
new RESTfulRouter(true) to open strict mode.
In this mode, uri will matches strictly and new <name> style syntax was introduced.
eg.
'/user/<name>' will match '/user/micheal', but not match '/user/micheal/age', also not match '/user/micheal/'.
Type filter supported by <name:filter>.
Current filters
- int : pure number
eg.
'/user/<id:int>' will match '/user/123, but not match '/user/micheal'.
Because it base on YAF\Route\Regex, some regex can be used.
And currently you can't use '()', it will cause error.
eg.
'/blog/?' will match '/blog' or '/blog/'.
Class: AdaptiveView
Render with different way(renderer) according to view file's extension name.
Use default Yaf Simple View as fallback if no renderer matched.
$view = new AdaptiveView($path = '{yaf.application.directory}/views/')
- $path String: path of view files located, default is '{yaf.application.directory}/views/'
Create a view.
$view->on($extname, $renderder)
- $extname String: view file's extension name
- $renderer($file, $data) Function: called when extname matched, should
returnthe rendered result.
Register a renderer with extname.
$view->*
Other common methods see Yaf/View/Interface
Example
Bootstrap.php
Now you can use this view in YourController.php
Class: ExtendedController
Common controller base on \Yaf\Controller_Abstract with many useful methods;
flash
Flash messaging
$this->flash($msg, $type = 'info')
Store message for next request
$this->flashNow($msg, $type = 'info')
For current request
$this->getFlash()
Retrieve message for current request