codeigniter-4grocery-crud

Getting "Class 'GroceryCrud\Core\GroceryCrud' not found" at the installation of Grocery CRUD


After installing Grocery CRUD Enterprise at my Codeigniter 4 project, I am getting the following error:

Class 'GroceryCrud\Core\GroceryCrud' not found

Am I missing something? I've followed the instructions of the Installation guide but there is nowhere showing how to resolve this.


Solution

  • This is a very common mistake when you install Grocery CRUD Enterprise without composer. Since the library is not loaded through PSR-4 that is used from composer, the library needs to be explicitly called through the function include.

    More specifically if your Controller starts with those lines:

    <?php
    namespace App\Controllers;
    
    use Config\Database as ConfigDatabase;
    use Config\GroceryCrud as ConfigGroceryCrud;
    use GroceryCrud\Core\GroceryCrud;
    

    You should add the below include right after the line namespace App\Controllers;

     include(APPPATH . 'Libraries/GroceryCrudEnterprise/autoload.php');
    

    So your new Controller will look like this:

    <?php
    namespace App\Controllers;
    
    // This is required
    include(APPPATH . 'Libraries/GroceryCrudEnterprise/autoload.php');
    
    use Config\Database as ConfigDatabase;
    use Config\GroceryCrud as ConfigGroceryCrud;
    use GroceryCrud\Core\GroceryCrud;