CodeIgniter 4 Dual-Mode and IgniteCore SDK for Perfex CRM

Build Dual-Mode CodeIgniter 4 Modules with IgniteCore SDK

Writing Perfex CRM modules strictly with CodeIgniter 3 globals limits IDE autocompletion, blocks unit testing, and complicates Composer dependency management. With the IgniteCore SDK, you can scaffold dual-mode modules that run clean CodeIgniter 4 PSR-4 controllers, services, and migrations when IgniteCore is present, while gracefully falling back to standard CI3 hooks on unbridged Classic installations without shipping two separate zip packages.

New to the runtime model? Check why teams choose CI4 dual-mode on Classic over early Next 1.0 rewrites.

Module ComponentLegacy CI3 LocationIgniteCore Dual-Mode Location
Bootstrap & Menu Hooksmodules/{slug}/{slug}.phpmodules/{slug}/{slug}.php (shared thin loader)
Controllers & Filterscontrollers/*.php (CI_Controller)ci4/app/Controllers/*.php (BaseController)
Database Modelsmodels/*_model.phpci4/app/Models/*.php (IgniteModel)
Route Registrationconfig/routes.phpci4/app/Config/Routes.php
Manifest & Capability CheckHeader docblock onlyignitecore.json + docblock metadata

1. Scaffold the Dual-Mode Directory Layout

Keep your root module file clean and declarative so Perfex Classic discovers activation, deactivation, and uninstall hooks natively. Inside the same module folder, place your CodeIgniter 4 namespace under ci4/ and declare an ignitecore.json manifest so IgniteCore auto-registers PSR-4 paths on boot. Follow the IgniteCore installation guide to prepare your local dev sandbox first.

  • Add defined('BASEPATH') or exit('No direct script access allowed'); at the top of all Classic entry scripts and install.php.
  • Define a unique PSR-4 root namespace (such as Vendor\ModuleSlug) in ignitecore.json to prevent class collisions.
  • Use IgniteCore’s ignite_is_active() helper inside your menu hook to route admin links to CI4 or CI3 fallback controllers.

2. Share Auth, Permissions, and Database Connections

Your CI4 controllers must enforce the exact same Perfex staff roles and client permissions as Classic views. Inject IgniteCore’s PerfexAuthFilter on admin routes, query db_prefix() dynamically via IgniteDatabase, and validate modules with the IgniteCore Compatibility Scanner before packaging releases.

  • Apply perfex_auth and perfex_perm:your_capability,view route filters instead of checking $_SESSION manually.
  • Never hardcode tbl table prefixes; always resolve table names through $this->db->prefixTable() or IgniteCore helpers.
  • Wrap CI4 schema migrations inside idempotent if (! $this->db->tableExists(...)) guards matching install.php.

Common Pitfalls and Quick Fixes

  • Class not found errors inside ci4/ controllers: Verify your ignitecore.json PSR-4 folder path matches the directory casing on Linux servers (Controllers vs controllers).
  • CSRF 403 failures on AJAX POST requests from Classic admin views: Pass Perfex’s csrfData token in headers or configure the IgniteCore CSRF bridge for matching admin routes.
  • Unscoped Composer packages crashing older modules: Run composer install --no-dev inside your module only for unique libraries, or rely on IgniteCore’s shared SDK packages.

Frequently Asked Questions

Do I need to maintain two separate databases for dual-mode modules?

No. Both the CI3 fallback layer and the CodeIgniter 4 runtime connect to the exact same Perfex CRM MySQL database and table prefix. IgniteCore reads Classic’s database configuration automatically so records created in CI4 appear immediately inside standard Classic admin reports.

Can a dual-mode module render inside Perfex’s native admin sidebar layout?

Yes. IgniteCore provides a view wrapper helper that injects your CodeIgniter 4 module HTML cleanly inside Perfex’s standard header, sidebar navigation, and footer assets, keeping custom Tailwind or Bootstrap styles scoped tightly without breaking core admin page layouts or global JavaScript.

How should I test dual-mode CI4 modules before releasing to customers?

Run PHPUnit tests against your PSR-4 domain services, execute Playwright smoke tests on both CI4-enabled and CI3-fallback Perfex instances, and scan the final zip package with the IgniteCore Compatibility Scanner to verify zero PHP syntax errors, missing guards, or hook conflicts.

Can existing Perfex CI3 modules be converted incrementally to dual-mode?

Yes. You can leave legacy views and admin hooks running in CI3 while moving complex APIs, report exporters, and webhook handlers into ci4/ one endpoint at a time using IgniteCore’s progressive Strangler Fig migration pattern without halting active feature releases.


Comments

Leave a Reply

Your email address will not be published.Required fields are marked *