1

I'm rebuilding a component called DogWalk for Joomla 4 and I've tried to ensure I'm doing exactly what the core Banners component does. I've named and namespaced my files, named my directories identically to how Banners does it, but I can't get the BaseController to find my view file.

I'm dumping the $this->paths array from BaseController::createView, and the path is the same for Banners and for DogWalk:

array (size=1)
  'view' => 
    array (size=1)
      0 => string '/Users/mystuff/Sites/joomla4/administrator/components/com_dogwalk/views/'

However my component is looking for a file called mycomponentViewviewname while the actual view class name for Banners (and all the other admin components) is just HtmlView. Furthermore the Banners view class is found even though it's in View, not views (despite what $config array says).

How do I define where the controller will find my views, and what naming convention they would use?

  • Is your component properly namespaced? Is its record present in libraries/autoload_psr4.php file? – Sharky Dec 6 at 6:26
  • You know that you really do not have to define any location for the view since the controller automatically finds it. You see the createView() and getView() methods of the BaseController, then you of course know how it finds the view, if you set your component correctly. I do not really see any good answer on your question here, since most probably you'll will find a typo as usually these questions end up... – Zollie Dec 6 at 9:46
  • @Sharky there is no line for my component in the libraries/vendor/composer/autoload_psr4.php file-- should that be automatically reloaded when you install a component? – user101289 yesterday
  • You are looking at the wrong file. The file I mentioned, libraries/autoload_psr4.php, should get updated when installing extensions if Extension - Namespace Updater plugin is enabled. – Sharky yesterday
  • @Sharky thanks, I verified that the plugin was working as expected and had added the namespace in the libraries/autload_psr4.php. Still not loading the files, but at least we can rule that out. – user101289 16 hours ago
1

The view file that your component is looking for MycomponentViewViewname which was used in the Joomla 3, so make sure you are extending the right controller class in your Controller(i.e Joomla\CMS\MVC\Controller\BaseController or any other class extending it such as AdminController). If it is from correct namespace track the setView() for any such changes that can cause the problem.

If this doesn't solve your problem then debugging the whole flow will be the option. But before that, I will suggest running the extension on some other fresh Joomla 4 setup on default parameters(as maybe some changes are affecting it such as code changes or plugin overrides).

If you are unable to find any solution you can override the setView() method in your controller as per your need(this should be the last option).

Hope this might help. Do let us know the solution once you find it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.