Nightly Build - Error: Parser is unable to parse the response

Hello everyone! :blush:

I was trying to install and configure the nightly build: grocery-crud-enterprise-3.0.0-beta.3. All are going well except that when I am about to load the page an error displays which says:
“Error: Parser is unable to parse the response”
Parser

I tried searching the forums and haven’t seen any similar situation so I decided to ask for help.

Thank you in advance.

Hello @larasmith ,

It is great that you are trying the Beta version :grinning:

This error means that probably the Route is not configured correctly for the your controller function name. Can you please check if:

  • The app.baseURL on .env if it is the correct one?
  • Check the file: app/Config/Routes.php that it is configured correctly

If this still doesn’t work then it is probably an issue with the .htaccess file. Try renaming .htaccess to .htaccess2 (just to rename it) and try to have the same URL but with index.php at the front. For example: your-url-codeigniter-4/index.php/example/customers instead of your-url-codeigniter-4/example/customers

Let me know if any of the above worked for you.

If not can you please copy the Controller that you use and the app/Routes.php file to see it?

Regards
Johnny

1 Like

Hello @johnny !

I have checked the app.baseURL on .env also the app/Config/Routes.php.
I also tried renaming the .htaccess file just like you said but it still doesn’t work.

Here is the copy of the code in the controllers I am working on:
example.php:

namespace App\Controllers;

//include(APPPATH . 'Libraries/GroceryCrudEnterprise/autoload.php');
use GroceryCrud\Core\GroceryCrud;

class Example extends BaseController
{
    public function index() 
    {
        $output = (object)[
            'css_files' => [],
            'js_files' => [],
            'output' => ''
        ];

        return $this->_example_output($output);
    }
    public function customers()
    {
        $crud = $this->_getGroceryCrudEnterprise();

        $crud->setCsrfTokenName(csrf_token());
        $crud->setCsrfTokenValue(csrf_hash());

        $crud->setTable('tblwn');
        $crud->setSubject('Customer', 'Customers');

        $output = $crud->render();

        return $this->_example_output($output);
    }

    private function _example_output($output = null) {
        if (isset($output->isJSONResponse) && $output->isJSONResponse) {
                    header('Content-Type: application/json; charset=utf-8');
                    echo $output->output;
                    exit;
        }

        return view('example.php', (array)$output);
    }

    private function _getDbData() {
        $db = (new \Config\Database())->default;
        return [
            'adapter' => [
                'driver' => 'Pdo_Mysql',
                'host'     => $db['hostname'],
                'database' => $db['database'],
                'username' => $db['username'],
                'password' => $db['password'],
                'charset' => 'utf8'
            ]
        ];
    }
    private function _getGroceryCrudEnterprise($bootstrap = true, $jquery = true) {
        $db = $this->_getDbData();
        $config = (new \Config\GroceryCrudEnterprise())->getDefaultConfig();

        $groceryCrud = new GroceryCrud($config, $db);
        return $groceryCrud;
    }
}

Routes.php:

<?php

namespace Config;

// Create a new instance of our RouteCollection class.
$routes = Services::routes();

/*
 * --------------------------------------------------------------------
 * Router Setup
 * --------------------------------------------------------------------
 */
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
// The Auto Routing (Legacy) is very dangerous. It is easy to create vulnerable apps
// where controller filters or CSRF protection are bypassed.
// If you don't want to define all routes, please use the Auto Routing (Improved).
// Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true.
// $routes->setAutoRoute(false);

/*
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/', 'Home::index');

/*
 * --------------------------------------------------------------------
 * Additional Routing
 * --------------------------------------------------------------------
 *
 * There will often be times that you need additional routing and you
 * need it to be able to override any defaults in this file. Environment
 * based routes is one such time. require() additional route files here
 * to make that happen.
 *
 * You will have access to the $routes object within that file without
 * needing to reload it.
 */
if (is_file(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) {
    require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php';
}

// Make sure that you always add get and post functions
$routes->get('/example/customers', 'Example::customers');
$routes->post('/example/customers', 'Example::customers');

Thanks for the response regarding this. :blush: