Class Phalcon\Mvc\Router\Group

Helper class to create a group of routes with common attributes

  1. <?php
  2. $router = new \Phalcon\Mvc\Router();
  3. //Create a group with a common module and controller
  4. $blog = new Group(array(
  5. 'module' => 'blog',
  6. 'controller' => 'index'
  7. ));
  8. //All the routes start with /blog
  9. $blog->setPrefix('/blog');
  10. //Add a route to the group
  11. $blog->add('/save', array(
  12. 'action' => 'save'
  13. ));
  14. //Add another route to the group
  15. $blog->add('/edit/{id}', array(
  16. 'action' => 'edit'
  17. ));
  18. //This route maps to a controller different than the default
  19. $blog->add('/blog', array(
  20. 'controller' => 'about',
  21. 'action' => 'index'
  22. ));
  23. //Add the group to the router
  24. $router->mount($blog);

Methods

public __construct ([unknown $paths])

Phalcon\Mvc\Router\Group constructor

public Phalcon\Mvc\Router\Group setHostname (unknown $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 (unknown $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 (unknown $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 (unknown $pattern, [unknown $paths], [unknown $httpMethods])

Adds a route applying the common attributes

public Phalcon\Mvc\Router\Route add (unknown $pattern, [unknown $paths], [unknown $httpMethods])

Adds a route to the router on any HTTP method

  1. <?php
  2. router->add('/about', 'About::index');

public Phalcon\Mvc\Router\Route addGet (unknown $pattern, [unknown $paths])

Adds a route to the router that only match if the HTTP method is GET

public Phalcon\Mvc\Router\Route addPost (unknown $pattern, [unknown $paths])

Adds a route to the router that only match if the HTTP method is POST

public Phalcon\Mvc\Router\Route addPut (unknown $pattern, [unknown $paths])

Adds a route to the router that only match if the HTTP method is PUT

public Phalcon\Mvc\Router\Route addPatch (unknown $pattern, [unknown $paths])

Adds a route to the router that only match if the HTTP method is PATCH

public Phalcon\Mvc\Router\Route addDelete (unknown $pattern, [unknown $paths])

Adds a route to the router that only match if the HTTP method is DELETE

public Phalcon\Mvc\Router\Route addOptions (unknown $pattern, [unknown $paths])

Add a route to the router that only match if the HTTP method is OPTIONS

public Phalcon\Mvc\Router\Route addHead (unknown $pattern, [unknown $paths])

Adds a route to the router that only match if the HTTP method is HEAD

public clear ()

Removes all the pre-defined routes