CI4 for Perfex CRM By Head Random • 2026-11-26 12:30 PM

Build Dual-Mode CodeIgniter 4 Modules for Perfex CRM with IgniteCore SDK

227.90 ms

Perfex CRM module authors can adopt CodeIgniter 4.7.6 (PHP 8.2+, strict typing, PSR-4 namespaces, and route filters) without forcing buyers to install IgniteCore. By adding a self-contained ignite/ directory and a manifest.php v1 contract inside an existing module, your routes accelerate on IgniteCore when available and fall back 100% natively to CodeIgniter 3.1.11 when IgniteCore is absent.

Why Dual-Mode Architecture Solves Perfex CRM Dependencies

Perfex CRM runs on CodeIgniter 3.1.11, where App_Controller.php halts if CI_VERSION differs from 3.1.11, and both kernels share colliding constants (APPPATH, FCPATH, ENVIRONMENT) and helper names. Booting CI4 inside CI3 is not viable, yet requiring every buyer to install a second runtime adds friction.

IgniteCore solves this via a Pre-Boot Front-Dispatcher (modules/ignite_core/bootstrap/dispatcher.php) and a zero-coupling Dual-Mode SDK:

  • Zero hard dependency: Standard Perfex entry files ({slug}.php, CI3 controllers, config/my_routes.php, models, views) remain untouched and fully operational on CI3.
  • Mutually exclusive execution: Matched routes enabled in runtime/writable/cache/route_manifest.php boot pure CodeIgniter 4.7.6 inside modules/ignite_core/runtime/, while unmatched routes pass straight to root index.php on CI3.
  • Future-proof ignite/ naming: Using modules/{slug}/ignite/ instead of ci4/ keeps module contracts intact when IgniteCore upgrades runtime/system/ to CodeIgniter 4.8+, 5.x, or 6.x.

Standard Dual-Mode Directory Layout

Keep CI3 code at the module root and isolate the PHP 8.2+ CI4 layer under ignite/:

modules/your_module/
├── your_module.php              # Standard Perfex CI3 bootstrap, hooks, and menus
├── config/
│   ├── my_routes.php            # Standard CI3 routes (100% preserved fallback)
│   └── csrf_exclude_uris.php    # Modular CSRF exclusions shared by CI3 & CI4
├── controllers/                 # Legacy CI3 controllers
└── ignite/                      # Zero-coupling Dual-Mode runtime layer
    ├── manifest.php             # Schema v1 discovery, PSR-4, and route contract
    ├── Config/Routes.php        # CodeIgniter 4 RouteCollection definitions
    ├── Filters/                 # Optional module-specific CI4 Route Filters
    └── Controllers/             # Pure CI4 PSR-4 controllers (PHP 8.2+)

The ignite/manifest.php Schema v1 Contract

Ignite_core_manifest_builder::discoverModuleManifests() scans active rows in tblmodules (active = 1) for modules/{slug}/ignite/manifest.php, loading each inside an isolated try/catch block so a broken manifest never disrupts the CRM.

<?php

declare(strict_types=1);

return [
    'schema_version' => 1,
    'module_slug'    => 'your_module',
    'display_name'   => 'Your Module',
    'engine_min'     => '4.7.0',
    'psr4'           => [
        'Modules\\YourModule\\Ignite' => __DIR__,
    ],
    'routes_file'    => __DIR__ . '/Config/Routes.php',
    'events_file'    => null,
    'commands'       => [],
    'benchmark_ci3_targets' => [
        [
            'id'       => 'your_module_ci3_status',
            'name'     => 'Your Module (CI3)',
            'endpoint' => '/your_module/api/v1/status',
        ],
    ],
    'route_entries'  => [
        [
            'key'      => 'api_v2_status',
            'methods'  => ['GET'],
            'type'     => 'exact',   // 'exact' | 'prefix' | 'regex'
            'match'    => 'api/v2/your_module/status',
            'default'  => true,
            'priority' => 100,       // Lower evaluates first
            'label'    => 'Your Module CI4 Status Endpoint',
        ],
    ],
];
  • schema_version, engine_min, psr4, routes_file, events_file, commands: Declare contract v1, minimum CI4 engine (4.7.0), dynamic PSR-4 namespace registration, CI4 routes file, optional boot events file, and optional Spark commands.
  • benchmark_ci3_targets: Optional array (up to 5 endpoints starting with /) surfaced alongside CI4 routes in Setup > IgniteCore > Diagnostics & Guard.
  • route_entries: Each item maps to a toggle in tblignite_core_route_toggles. Set type (exact, prefix, or regex), methods (['GET'], ['POST'], ['ANY']), priority (sorted ascending), and default (true for new api/v2/* routes, false for opt-in Strangler Fig routes overlapping my_routes.php).

Base Controllers, Shared Bridges, and Route Filters

IgniteCore provides shared infrastructure under IgniteCore\ (modules/ignite_core/runtime/app/).

1. Built-in Base Controllers

  • IgniteCore\Controllers\BaseAdminController: Injects $this->auth, $this->options, $this->lang, and $this->outbox, syncs active_language, and provides jsonSuccess() and jsonError().
  • IgniteCore\Controllers\BaseClientController: Injects $this->auth, $this->options, and $this->lang for Client Portal endpoints with jsonSuccess().
  • IgniteCore\Controllers\BaseApiController: Injects $this->options and provides apiSuccess(mixed $data, array $meta = [], int $statusCode = 200) plus RFC 9457 apiProblem() (application/problem+json).

2. Shared-State Bridges via service()

Service Call Bridge Class Capabilities
service('perfexAuth') PerfexAuthService staff(), isAdmin(), staffCan($capability, $feature), contact(), isStaffLoggedIn(), isClientLoggedIn(), touchStaffActivity()
service('perfexOptions') PerfexOptionsService get($name, $default) and set($name, $value, $autoload) with preloaded tbloptions cache
service('perfexLang') PerfexLangService setLanguage(), loadModule($slug), line($key, $slug, ...$args) for native *_lang.php packs
service('perfexOutbox') PerfexEventOutboxService enqueue($eventName, $payload, $ci3HookName) into tblignite_core_event_outbox for CI3 after_cron_run hook relay

3. All 6 Built-in Route Filters

Configured in runtime/app/Config/Filters.php:

  1. staffAuth (PerfexStaffAuthFilter): Validates Perfex Staff SSO via tblsessions (unprefixed ID + INT(10) UNIX timestamp) and throttles last_activity updates.
  2. staffCan (PerfexStaffPermissionFilter): Default-deny RBAC filter (such as staffCan:view,your_module) checking tblstaff_permissions.
  3. clientAuth (PerfexClientAuthFilter): Validates Client Portal contact sessions (tblcontacts).
  4. perfexCsrf (PerfexCsrfFilter): Validates Perfex csrf_cookie_name against POST/JSON csrf_token_name or X-CSRF-TOKEN without regenerating the cookie, returning 419 on AJAX mismatch.
  5. apiAuth (PerfexApiAuthFilter): Stateless API guard closing any active PHP session and setting X-IgniteCore-Kernel, X-Content-Type-Options: nosniff, and Referrer-Policy.
  6. sessionReadOnly (SessionReadOnlyFilter): Calls session_write_close() right after auth checks to prevent AJAX session locking.
<?php

use CodeIgniter\Router\RouteCollection;

/** @var RouteCollection $routes */
$routes->get(
    'api/v2/your_module/status',
    '\Modules\YourModule\Ignite\Controllers\StatusController::index',
    ['filter' => 'apiAuth']
);

$routes->post(
    'admin/your_module/save_settings',
    '\Modules\YourModule\Ignite\Controllers\AdminSettingsController::save',
    ['filter' => ['perfexCsrf', 'staffAuth', 'staffCan:edit,your_module']]
);

Migrating CSRF Exclusions to config/csrf_exclude_uris.php

Because my_routes.php only loads in CI3, move stateless API exclusions out of $app_csrf_exclude_uris into modules/{slug}/config/csrf_exclude_uris.php:

<?php

defined('BASEPATH') or exit('No direct script access allowed');

return [
    'api/v2/your_module/.+',
];

Both Perfex InitModules and Ignite_core_manifest_builder::collectPerfexCsrfExcludeUris() merge every module's file into route_manifest.php, keeping CSRF rules consistent across CI3 and CI4.

Scaffolding and Managing Modules with Spark CLI

IgniteCore ships four Spark CLI commands (php modules/ignite_core/spark, guarded by PHP_SAPI !== 'cli'):

php modules/ignite_core/spark ignite:doctor
php modules/ignite_core/spark ignite:make-module your_module
php modules/ignite_core/spark ignite:manifest
php modules/ignite_core/spark ignite:entry status
  • ignite:doctor: Verifies PHP >= 8.2, ext-intl, ext-mbstring, ext-mysqli, DB connectivity, tblsessions schema, and entry mode.
  • ignite:make-module <slug> [--target <dir>]: Scaffolds ignite/manifest.php, Config/Routes.php, and Controllers/StatusController.php.
  • ignite:manifest: Discovers active Dual-Mode modules and recompiles runtime/writable/cache/route_manifest.php.
  • ignite:entry [status|attach-index|detach]: Manages the 3-line index.php marker on Nginx, OpenLiteSpeed, or CyberPanel servers.

Zero Hard-Dependency Guarantee

Perfex CRM only loads root {slug}.php, config/my_routes.php, and CI3 controllers/, never scanning ignite/. Buyers without IgniteCore run 100% on CI3; if IgniteCore is added later, ignite:manifest activates CI4 routes automatically; and if IgniteCore is disabled or passed ?ignite_fallback=1, the 5-layer Circuit Breaker routes traffic cleanly back to CI3.

Frequently Asked Questions

Will my Dual-Mode module break on PHP 8.1 or without IgniteCore?

No, as long as your CI3 files support PHP 8.1+. Perfex CI3 never includes modules/{slug}/ignite/, and IgniteCore's Circuit Breaker only boots CI4 when PHP_VERSION_ID >= 80200, ext-intl, and ext-mbstring are present.

How do CI4 controllers notify legacy CI3 module hooks?

Call service('perfexOutbox')->enqueue('event_name', ['id' => 42], 'your_ci3_hook'). IgniteCore queues the payload in tblignite_core_event_outbox, and Perfex's after_cron_run hook relays up to 50 events per cycle to hooks()->do_action().

What happens if a CI4 module route throws an unhandled exception?

Config\Exceptions::handler() logs attribution via PerfexIncidentGuard::record(). With Auto-Quarantine enabled (3 incidents in 300 seconds), IgniteCore automatically disables that module's CI4 routes and reverts traffic to CI3.

Why use ignite/ instead of ci4/?

Naming the directory ignite/ and namespace Modules\{StudlySlug}\Ignite keeps module contracts compatible across future CodeIgniter 4.8+, 5.x, or 6.x runtime upgrades.

If your business runs third-party Perfex add-ons whose original authors have not added ignite/manifest.php support yet, HeadRandom provides custom upgrading and porting of existing Perfex modules to run on IgniteCore CodeIgniter 4.

Related Guides

HeadRandom Perfex CRM Engineering

Need a Custom Perfex CRM Module, Bug Fix, or CodeIgniter 4 Upgrade?

Avoid broken updates, PHP 8.2-8.4 errors, and risky core edits. HeadRandom provides custom Perfex CRM module development, upgrade, and bug-fixing services for any third-party or custom module on your Perfex CRM installation, plus upgrading Perfex CRM from CodeIgniter 3 to CodeIgniter 4 via IgniteCore for Perfex CRM.

Build, Upgrade & Fix Any Perfex CRM Module

Develop new custom modules from scratch, patch bugs or hook conflicts on existing client modules, and update legacy code for clean PHP 8.2-8.4 compatibility with zero core file hacks. View Perfex CRM module development scope.

CodeIgniter 3 to CodeIgniter 4 via IgniteCore

Migrate your Perfex CRM runtime to CodeIgniter 4 (4.7.6) using IgniteCore for Perfex CRM (independent module by HeadRandom) with Dual-Mode CI3 fallback, 32% to 75% lower latency, 50% less RAM, and custom CI4 porting for third-party modules. See CI3 to CI4 upgrade options.

40+ Commercial Modules Published100% Zero Core File Edits0 High Security Audit GateTransparent Pricing from $39

Combine 2+ HeadRandom services (Custom Module, IgniteCore CI4 Upgrade, or Website Care) to save 30% automatically.