- Phalcon Tutorial
- Phalcon - Home
- Phalcon - Overview
- Phalcon - Environmental Setup
- Phalcon - Application Structure
- Phalcon - Functionality
- Phalcon - Configuration
- Phalcon - Controllers
- Phalcon - Models
- Phalcon - Views
- Phalcon - Routing
- Phalcon - Database Connectivity
- Phalcon - Switching Databases
- Phalcon - Scaffolding Application
- Phalcon - Query Language
- Phalcon - Database Migration
- Phalcon - Cookie Management
- Phalcon - Session Management
- Phalcon - Multi-Lingual Support
- Phalcon - Asset Management
- Phalcon - Working with Forms
- Phalcon - Object Document Mapper
- Phalcon - Security Features
- Phalcon Useful Resources
- Phalcon - Quick Guide
- Phalcon - Useful Resources
- Phalcon - Discussion
Phalcon - Routing
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 application has two modes −
- MVC mode
- Match-only mode
The first mode is ideal for working with MVC applications. 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.
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 Phalcon\Mvc\Router(); $router->add('/login', array( 'controller' => 'users', 'action' => 'login', )); return $router;
Output
The code will produce the following output −
Advertisements