GeniXCMS

Router Class

categoryAPI edit_calendar31 Mar 2026

Router (Smart URL Engine)


The Router class is the core component responsible for parsing "Smart URLs" (Permalinks) and mapping them to specific system controllers and parameters. It supports robust, regex-based routing and allows for granular extension by third-party modules.


πŸ—ΊοΈ Routing Architecture

The router uses a predefined map of URI patterns that are matched against the incoming request. This system supports language prefixes, category structures, and custom module routes.

πŸ“œ Common Pattern Examples

URI Pattern Parameter Result Description
category/([0-9]+)/(.*)/ cat=ID Standard category archive archives.
tag/(.*)/ tag=SLUG Tag-based content filtering.
([a-z]{2})/mod/(.*).html mod=NAME, lang=XX Module routes with language prefixes.
rss/ rss Native RSS feed generation.

⚑ Core Methods

Router::run()

The primary execution point of the routing engine. This method performs several critical tasks:

  1. URI Detection: Identifies the requested path, automatically handling installations in subdirectories.
  2. Pattern Matching: Compares the URI against the internal routing map.
  3. Parameter Extraction: Returns a structured array of matched parameters upon success.

Router::add(array $routes)

Enables modules to register custom routing rules dynamically. New routes are automatically sorted to ensure that the most specific patterns are matched first.

// Registering a new custom route for a module
$my_route = [
    'product/([0-9]+)/' => [
        'product' => 1
    ]
];
Router::add($my_route);

πŸ› οΈ Specialized URL Handling

GeniXCMS's routing engine is designed with high flexibility to support various server environments and SEO requirements.

  • 🌍 Locale Support: The router automatically detects 2-letter ISO language codes (e.g., /en/, /id/) at the beginning of the URL and passes them as a lang parameter to the controller.
  • πŸ“ Subdirectory Intelligence: If GeniXCMS is installed in a folder (e.g., yoursite.com/cms/), the router strips the /cms/ prefix automatically before processing.
  • πŸ”— Permalink Flexibility: Seamlessly falls back to index.php based routes if Apache's mod_rewrite (or equivalent Nginx configuration) is unavailable.

βš™οΈ URL Metadata & Suffixes

The routing engine respects the GX_URL_PREFIX constant (default: .html). This ensures that generated links and internal routes maintain consistent aesthetics across the entire application.

lightbulb
TipRegex Power: When adding custom routes, you can use capture groups (e.g., (.*)) and map them to their corresponding numerical indexes in your parameter array. This allows for highly dynamic and clean URL structures.

See Also

  • Control Layer β€” How the parameters returned by the router are dispatched to controllers.
  • Smart URL Guide β€” Configuring SEO-friendly URLs in the admin panel.