English 中文(简体)
Phalcon - Routing
  • 时间:2024-12-22

Phalcon - Routing


Previous Page Next Page  

The router component allows to define routes that are mapped to the controllers or handlers that should receive the request. A router parses a URI as per the information received.

Every router in the web apppcation has two modes −

    MVC mode

    Match-only mode

The first mode is ideal for working with MVC apppcations. Following is the syntax to define a route in Phalcon.

$router = new Router();  

// Define a route 

$router->add( 
   "<URI-Name>", 
   [ 
      "controller" => "<controller-name>", 
      "action"     => "<action-name>", 
   ] 
);

Example

For searching a category, let us create a route in routes.php of config folder.

Routes

Consider creating a route which will call a method login as we invoke “UsersController”. In such a case, it is suggested to create a route which maps the given URL.

<?php  

$router = new PhalconMvcRouter();  

$router->add( /login , array( 
    controller  =>  users , 
    action  =>  login , 
));
  
return $router; 

Output

The code will produce the following output −

Output Code Advertisements