PHP Car RentalUser Manual Visit PHP Car Rental →
Customizing & Technical

Adding modules and admin pages

The script is meant to be edited. Adding a module or an admin page takes one file.

A new website module

  1. Create extensions/my_module.php. Print the HTML you want; it is placed in the template.
  2. Open it with index.php?mod=my_module, or attach it to a page in Pages and menu (field Module).
  3. Set $pageData['title'], $pageData['subtitle'], $pageData['meta_description'] inside the file to control the title banner and the SEO.
<?php
if (!defined('IN_CMS')) die('');
$pageData['title'] = 'Special offers';
$cars = new CarModel($database);
foreach ($cars->featured(3) as $car) {
    echo render_car_card($car);
}

Inside a module these variables are available: $database, $DBprefix, $website (current language and settings) and $pageData. Useful helpers: setting(), __(), e(), money(), mod_link(), car_link(), csrf_field(), send_mail().

A new admin page

  1. Create ADMIN/<category>/<action>.php.
  2. Add it to ADMIN/pages_structure.php with a label and a permission slug.
  3. Add the permission to the admin_permissions table so you can give it to groups (Administrators, groups and permissions).

In an admin page, $admin is the UI object (ui_title(), ui_table(), ui_form(), show_pagination()) and $database the database. Two helpers save a lot of code: admin_crud() builds a complete list + add/edit/delete screen from a small configuration, and admin_settings_form() builds a tabbed settings page. See ADMIN/car_settings/brands.php (14 lines) and ADMIN/settings/mail.php for examples.

Every POST form in the admin gets a security token automatically; in your own front end forms add <?= csrf_field() ?> and check it with csrf_check().

Database access

Use the class DatabasePDO: $database->Query($sql, $params) with prepared parameters, DataArray(), SQLCount_Query() and others. Table names carry the prefix from config.php.

Last updated