Table Of ContentsPrevious topic< Class Phalcon\Mvc\Router\Exception Next topic |
Class Phalcon\Mvc\Router\Group¶Helper class to create a group of routes with common attributes <?php
$router = new Phalcon\Mvc\Router();
//Create a group with a common module and controller
$blog = new Phalcon\Mvc\Router\Group(array(
'module' => 'blog',
'controller' => 'index'
));
//All the routes start with /blog
$blog->setPrefix('/blog');
//Add a route to the group
$blog->add('/save', array(
'action' => 'save'
));
//Add another route to the group
$blog->add('/edit/{id}', array(
'action' => 'edit'
));
//This route maps to a controller different than the default
$blog->add('/blog', array(
'controller' => 'about',
'action' => 'index'
));
//Add the group to the router
$router->mount($blog);
Methods¶public __construct ([array $paths]) Phalcon\Mvc\Router\Group constructor public Phalcon\Mvc\Router\Group setHostname (string $hostname) Set a hostname restriction for all the routes in the group public string getHostname () Returns the hostname restriction public Phalcon\Mvc\Router\Group setPrefix (string $prefix) Set a common uri prefix for all the routes in this group public string getPrefix () Returns the common prefix for all the routes public Phalcon\Mvc\Router\Group beforeMatch (unknown $beforeMatch) Set a before-match condition for the whole group public string getBeforeMatch () Returns the before-match condition if any public Phalcon\Mvc\Router\Group setPaths (array $paths) Set common paths for all the routes in the group public array|string getPaths () Returns the common paths defined for this group public Phalcon\Mvc\Router\Route [] getRoutes () Returns the routes added to the group protected Phalcon\Mvc\Router\Route _addRoute () Adds a route applying the common attributes public Phalcon\Mvc\Router\Route add (string $pattern, [string/array $paths], [string $httpMethods]) Adds a route to the router on any HTTP method <?php
$router->add('/about', 'About::index');
public Phalcon\Mvc\Router\Route addGet (string $pattern, [string/array $paths]) Adds a route to the router that only match if the HTTP method is GET public Phalcon\Mvc\Router\Route addPost (string $pattern, [string/array $paths]) Adds a route to the router that only match if the HTTP method is POST public Phalcon\Mvc\Router\Route addPut (string $pattern, [string/array $paths]) Adds a route to the router that only match if the HTTP method is PUT public Phalcon\Mvc\Router\Route addPatch (string $pattern, [string/array $paths]) Adds a route to the router that only match if the HTTP method is PATCH public Phalcon\Mvc\Router\Route addDelete (string $pattern, [string/array $paths]) Adds a route to the router that only match if the HTTP method is DELETE public Phalcon\Mvc\Router\Route addOptions (string $pattern, [string/array $paths]) Add a route to the router that only match if the HTTP method is OPTIONS public Phalcon\Mvc\Router\Route addHead (string $pattern, [string/array $paths]) Adds a route to the router that only match if the HTTP method is HEAD public clear () Removes all the pre-defined routes public Phalcon\Mvc\Router\Group convert (string $name, callable $converter) Adds a converter to perform an additional transformation for certain parameter public array|null getConverters () Returns the router converter public Phalcon\Mvc\Router\Group setName (unknown $name) Set the name of the group public string getName () Returns the name of this group |