astridx/meinblog

Error: 0 Invalid controller class: display

Opened this issue · 7 comments

Chapter: The first view in the backend. Upon manually installing the component (via System | Install | Discover), the view of the component (in Components | COM_FOOS | COM_FOOS) displays the following error: Error: 0 Invalid controller class: display.

I'm using Joomla 4.1.4. I have installed the component per the instructions in two different Joomla sites with the same error code displayed. I have also deleted the autoload_psr4.php file (in /administrator/cache/) but the error code returns.
error-code

Is the code of the component you installed online, so that I can have a look?

Thank you for the fast reply! Yes, I do have the component installed online at: sundaytrekker.com. What credentials/info do you need to access the component online?

Update: The code finally worked correctly.

  • The code will only work correctly (and produce the message: Hello Foos) if you install the com_foos.zip via the Extensions:Install panel in the backend. The com_foos.zip is found in: 1-die-erste-ansicht-im-backend.
  • The code will not work if I follow the instructions found on page 48 under the heading 'Test you Joomla component'. The instructions direct the reader to 'copy the files manually in place' to the administrator and components folder of my Joomla 4 installation.

I compared all files from the zip archive and the manual-install files. The file DisplayController.php on line 43 has a difference:

  • zip archive DisplayController.php Line 43: public function display($cachable = false, $urlparams = ())
  • manual-install file DisplayController.php Line 43: public function display($cachable = false, $urlparams = [])

Would the square brackets [] and the parenthesis () difference cause the error to appear when manually copying the files?

When my Joomla 4 installation kept displaying the error code, I changed the square brackets to parenthesis in the file. I then refreshed the browser, cleared the browser cache, deleted the autoload_psr4.php file, and a few other common Joomla troubleshooting tasks, but the error code persisted. So finally, I solved the error code by installing the com_foos.zip file via the Extensions:Install panel.

Is there a typo in the manual-install files? Thank you for your attention and time! Most of all, thank you for writing and publishing your book!!

PS Should i manually copy the files to the live Joomla 4 installation so that the error code can present itself again?

PPS I almost forgot the second file difference is on the provider.php file:

  • zip archive provider.php Line 20: use Joomla\Component\Foos\Administrator\Extension\FoosComponent;
  • manual-install file provider.php Line 20: use FooNamespace\Component\Foos\Administrator\Extension\FoosComponent;

Hello Again! I wanted to give you an update. I was able to find out the specific reason the error code was displayed when manually copying the files to my Joomla 4 installation.

The problem is in the provider.php file (located: administrator/components/com_foos/services/provider.php). The error is caused by lines 41, 42, and 43.

Line 41 is: $container->registerServiceProvider(new CategoryFactory('\\NamespaceJoomla\\Component\\Foos'));
Line 41 needs to be changed to: $container->registerServiceProvider(new CategoryFactory('\\FooNamespace\\Component\\Foos'));

Line 42 is: $container->registerServiceProvider(new MVCFactory('\\NamespaceJoomla\\Component\\Foos'));
Line 42 needs to be changed to: $container->registerServiceProvider(new MVCFactory('\\FooNamespace\\Component\\Foos'));

Line 43 is: $container->registerServiceProvider(new ComponentDispatcherFactory('\\NamespaceJoomla\\Component\\Foos'));
LIne 43 needs to be changed to: $container->registerServiceProvider(new ComponentDispatcherFactory('\\FooNamespace\\Component\\Foos'));

The change of \\NamespaceJoomla\\Component\\Foos to \\FooNamespace\\Component\\Foos on all three lines solves the error code (after the files were manually copied and installed in my Joomla 4 installation.) I must alert you that for this to work and produce the correct result, the autoload_psr4.php file in /administrator/cache/plg_system_debug_administrator folder has to be deleted.

If the changes are made to the provider.php file BEFORE manually copying them to my Joomla 4 installation, the component is installed without any errors.

I hope this helps anyone else that runs into this issue. Is my solution the correct/final solution? Is this something that you may need to update in the file download here at github?

Again, thanks for your time and attention to this matter!

Thank you for your detailed explanation.
You are right. I have renamed namespace in a previous version from NamespaceJoomla to FooNamespace Maybe I forgot to make a correction at some point.

Unfortunately, I can't find the error in the current book version or in the current sample code.
Can you tell me where exactly you copied the code from.

@sundaytrekker Would the square brackets [] and the parenthesis () difference cause the error to appear when manually copying the files?

This is only a different Syntax https://www.php.net/manual/en/language.types.array.php

Hello! To answer from where exactly I copied the code from: I went to: https://github.com/astridx/boilerplate. Then, I clicked on the green code button and downloaded the zip file. If you download this zip file, you'll see the namespace errors.

A link on page 10 of your book Joomla 4.1L - Developing Extensions : Step by step to a working Joomla extension directed me to GitHub. I bought the Kindle edition of the book from amazon.com (USA). Here's the link to the page:

I have checked all provider.php files in the GitHub zip file tutorial chapters, and the namespace NamespaceJoomla appears in most (if not all) of them. These are the files that the reader (of the book) will manually copy into their Joomla 4 installation. And, like in my case, it will cause an error code to display.

I am reading and coding all of the chapters, and I have found another issue (a missing ;) that is causing another type of syntax error code. As I progress further in the tutorials, would you like me to make you aware of the errors? However, I do not want to be a thorn in your side.

The information is an excellent resource! I'm learning a lot. Thank you for creating the book and sharing your knowledge.

@sundaytrekker Thanks for your answer. In the repo https://github.com/astridx/boilerplate I checked the code. It is correct. Please check here:
https://github.com/astridx/boilerplate/blob/tutorial/src/administrator/components/com_foos/services/provider.php

What I'm noticing right now. Have you looked in the tutorial subdirectory? That doesn't contain the current code. Did I mention that in the book?