“Ooooops, something went wrong! If you can see this message, this is probably a misconfiguration in Grocery CRUD Enterprise!”

Having the “Ooooops, something went wrong! If you can see this message, this is probably a misconfiguration in Grocery CRUD Enterprise!” issue.

I did watch the video about fixing this problem, but it didn’t seem to help.

Here’s the basic info: PHP 8.2.x. CodeIgniter 4.7.4. GC 3.2.11 Enterprise. Not using composer, followed the wizard to the best of my ability.

Copied all the files into an existing (if barebones) CI project.

Base URL and pointer to the assets directory appears to be correct. in config/App.php I have public string $baseURL = 'http://localhost/precdb'; and in config/GroceryCrud.php I have 'assets_folder' => base_url() . '/vendor/grocery-crud/',

No errors related to GC show up in the browser console:


(the Type error seems to be related to a browser plugin I have, diigo).

I also created a test.html file and put it into public/vendor/grocery-crud. If, in my browser, I then go to http://localhost/precdb/vendor/grocery-crud/test.html, the test file correctly displays. So I think the path to the asset folder is correct?

The other thing that’s revealing is when I run in debug mode and put a breakpoint in my View file, for $js_files I see an array with one entry, http://localhost/precdb//vendor/grocery-crud/static/js/main.v3.2.11.2bf1c5db.js and for $css_files I see an array with zero entries…

And, sure enough, the source code for the resulting page shows that one js file and no css files.

So maybe js_files and css_files isn’t being generated correctly by $crud->render()?

Here’s my view file (listview):

    <div style='height:20px;'></div>  
<tr><td>
	<?php 
	foreach($css_files as $file): ?>
		<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
	 
	<?php endforeach; ?>
	<?php foreach($js_files as $file): ?>
	 
		<script src="<?php echo $file; ?>"></script>
	<?php endforeach; ?>


    <div>
        <?php echo $output; ?>
 
    </div>
    </td></tr>

and here’s the relevant part of the controller:

$output = $crud->render();
return $this->_example_output($output, $rawsearch);
...

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

		return view('header')
			. view('navbarbasic')
			. view('searchterms', array('searchtext' => $rawsearch))
			. view('listview', (array)$output)
			. view('footer');
	}

The other view files handle parts of the page not directly related to GC.

If you need to see other parts of my app, please let me know what and I’ll be happy to post it.

Thanks!

Hello @jgalak and thank you for the very detailed report. From a quick look it seems that the issue is that you load the JS files before the $output.

Please try to add the js_files on the bottom just before body or if this is not possible to at least be after the

<?php echo $output; ?>

So in your case it will be something like this:

    <div>
        <?php echo $output; ?>
 
    </div>
    </td></tr>
     ...
	<?php foreach($js_files as $file): ?>
	 
		<script src="<?php echo $file; ?>"></script>
	<?php endforeach; ?>
</body>

You are right, currently css_files are empty in the latest version so no need to add it.

Please let me know if that worked for you.

Regards
Johnny

That fixed the issue, but revealed another one. I’m not sure whether this is a GC problem or a CI problem (as I mentioned, I’m just learning CI4, all my prior use had been CI2 and 3):

The above error has gone away, but now I get this:

This message isn’t being shown in the main page, but in a “window” on the page. The header and footer views displayed correctly. So I think this is code generated by GC throwing this error?

Now, it’s correct that the method Result_c::getIndex() doesn’t have the right number of parameters. What I don’t understand is why it’s trying to call that method at all. getIndex, right now, is just a placeholder method that returns an “ok” status and does nothing else. The method that was called was Result_c::postResult_list_text(string $selection) that does have the right number of params.

But I can’t figure out why getIndex is being called at all. I’m not calling it explicitly from anywhere. Is this something that GC is doing? Did I mess up CI routing somewhere? I have the CI “auto routing (improved)” turned on, and the only hard routes I have in Routes.php are to another controller, basic_c.

The structure of the program is very simple at the moment: there is a controller basic_c which does nothing but display several views that present a form with a few dialogue options. When the form is submitted, it calls result/c/result_list_texts/text, which correctly calls the :postResult_list_text(string $selection)method of theresult_c` controller. This method generates the CRUD and returns several views one of which should display the GC-generated result.

So not sure why getIndex is being called at all…

I suspect this comes from my relying on knowledge of CI3 and GC 2 free version, and something is happening in either CI4 or GC 3 enterprise that I’m not understanding…

Further help much appreciated.

Hello @jgalak ,

I believe that this is a route issue. Few things that can come to mind:

in .env file, have you configured the variable app.baseURL = correctly? I guess yes since you have seen the video (but you never know).

Second part is to check your Routes, most probably you haven’t added the routes for the crud operations for example for the controller function customers

You should add both lines:

$routes->add('/example/customers', 'Example::customers');
$routes->add('/example/customers/(:segment)(/(:segment))?', 'Example::customers/$1/$2');

The second one is the most important since it is basically saying that the rout can have arguments plus that it supports get and post.

Let me know if that worked for you. If this is still doesn’t working, can you send us the url that is actually calling (you can find it from Inspect → Network) that is throwing the 404?

Regardfs
Johnny

Ah! I definitely did not add routes for the crud operations - I thought the autorouter would take care of that.

So coming from GC 2 Free, I am used to the controller being called once - the prior form would call the method on the controller, which would call GC to generate the data grid and insert that into the view that was generated by controller.

But now it almost looks like the controller is being called twice - first in the same way as above, but then the data grid itself is making a second call to pull the data. Maybe this is because GC3 enterprise is using an AJAX-type call to actually load the data? Am I understanding that correctly? Otherwise, I can’t figure out why getIndex() is ever being called…

I temporarily solved the problem by adding parameters to getIndex(), and then have it just call my expected method, but that doesn’t seem like a good solution. Definitely need to figure out the routing issue.

Actually, using the debugger, it seems like the controller is called three or more times. Once when the previous form is submitted, a second time after the headers and footers load on the resulting page but before the data grid window is created, and a third time after the data grid window is created, but before the data loads into it. And then once again each time I change pages in the data grid.

So definitely looks to me like AJAX (or equivalent) calls from the GC front end, triggering the controller.

The very first call directly calls my expected method, but all subsequent calls call getIndex(). Is there documentation somewhere of how GC forms these AJAX requests? Can they be customized?