Mecha CMS

Add extra functionality to the core engine.


Custom route files.

Download Stable Version Download Development Version

Something looks broken? We accept bounties to fix them faster.

v1.0.2178 Downloads
v1.0.1155 Downloads
v1.0.097 Downloads

Add some PHP files in .\lot\route folder:

└── lot\
    └── route\
        ├── user\
        │   └── register.php
        └── contact.php

Route files will automatically take effect on the existing site with an address according to the location of the route file, excluding the .php extension. For example, based on the file structure above, two routes will be applied:

Two global variables with name $id and $path are available to be used within the route file. $id refers to the value after the path, and $path refers to the route’s file path.

The following is an example contents of a route file:


$errors = 0;

// Validate request method
if (!Request::is('Post')) {
    Alert::error('Method not allowed.');

// Validate form token
if (!Guard::check(Post::get('token'), 'contact')) {
    Alert::error('Invalid token.');

// Redirect to the contact page immediately if there are some errors
if ($errors > 0) {

// Process the request data…
$from = '[email protected]';
$to = Post::get('email');
$title = Post::get('title');
$content = Post::get('content');
if (send($from, $to, $title, $content)) {
    Alert::success('Mail was sent successfully.');
} else {
    Alert::error('An error occurred while sending the mail.');

// Redirect to the contact page by default

Therefore you will be able to use that route as the form action in the HTML form element like so:

<form action="<?= $url; ?>/route/contact" method="post">
  <?= $alert; ?>
    <input name="title" required type="text">
    <input name="email" required type="email">
    <textarea name="content" required></textarea>
    <button type="submit">
      <?= i('Send'); ?>
  <input name="token" type="hidden" value="<?= token('contact'); ?>">