How can I create my own core controller in codeigniter 4 like codeigniter 3?

When you say "core" controller I understand you to mean a "base" controller which in CI v3 is often named MY_Controller. If that is what you are asking for it's actually much easier in v4 because of namespaces and the autoloader. Also, there is no need for the trickery of using a prefix like MY_.
Here's just how easy it is. The "base" controller...
File: /application/Controllers/Base.php
<?php namespace App\Controllers;
class Base extends \CodeIgniter\Controller
{
//your code here
}
Then extend the above to create any other controller
File: /application/Controllers/Home.php
<?php namespace App\Controllers;
class Home extends \App\Controllers\Base
{
// Your code here
}
The Home controller will inherit all the properties and methods you define in Base.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With