1

I'm currently building a new Joomla! 4 component from scratch by following along a series of blog posts since I am new to Joomla! and its development.

I am using Joomla! 4.1.5

Unfortunately I am not able to get the front-end part working while the back-end part works fine. I always get the "View not found" error when trying to visit any front-end site of the component.

The error shown is this:

404 View not found [name, type, prefix]: foo, html, foo\component\bar\site\controller\displayView

What I did is:

  1. Add a DisplayController to the site part with path com_foo/src/Controller/DisplayController.php
namespace Foo\Component\Bar\Site\Controller;

use Joomla\CMS\MVC\Controller\BaseController;

class DisplayController extends BaseController
{
    public function display($cachable = false, $urlparams = []): DisplayController
    {
        return parent::display($cachable, $urlparams);
    }
}
  1. Add a View to the site part with path com_foo/src/View/Foo/HtmlView.php
namespace Foo\Component\Bar\Site\View\Foo;

use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;

class HtmlView extends BaseHtmlView
{
    public function display($template = null)
    {
        parent::display($template);
    }
}
  1. Add a template with very basic content to the site part with path: com_foo/tmpl/foo/default.php
default template for foo part
  1. Install component (with uninstalling the old one before).
  2. Go to URL http://localhost/index.php?option=com_foo&view=foo
  3. The error is shown

1 Answer 1

2

I was able to resolve the issue. The DisplayController of the front-end part was lacking a proper constructor, once I added it the site part works as well.

namespace Foo\Component\Bar\Site\Controller;

use Joomla\CMS\MVC\Controller\BaseController;

class DisplayController extends BaseController
{
    public function __construct($config = [], MVCFactoryInterface $factory = null, ?CMSApplication $app = null, ?Input $input = null)
    {
        parent::__construct($config, $factory, $app, $input);
    }

    public function display($cachable = false, $urlparams = []): DisplayController
    {
        return parent::display($cachable, $urlparams);
    }
}

3
  • This shouldn't be necessary. When constructor is not present in child class, parent constructor is called. Which is what your constructor is doing.
    – Sharky
    Jul 26, 2022 at 7:57
  • @Sharky Due to having some custom logic in my constructor, my exact error was not having the constructor overloaded properly.
    – pollux
    Jul 28, 2022 at 15:42
  • You should have added this vital information to your question.
    – Sharky
    Aug 1, 2022 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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