Hello,
I am not sure if this really is a bug but after trying different things over the last few days, googling a lot about it, following different tutorials online I wasn't able to find the reason behind this.
Create a new component and add the following front-end files:
com_bar/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);
}
}
com_bar/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);
}
}
com_bar/tmpl/foo/default.php
default template for foo part
http://localhost/index.php?option=com_bar&view=foo
Component XML:
<!-- Frond-end files -->
<files folder="site/com_bar">
<folder>src</folder>
<folder>tmpl</folder>
</files>
<media folder="site/media" destination="com_bar/site">
<folder>css</folder>
<folder>js</folder>
<folder>img</folder>
</media>
<languages>
<language tag="en-GB">site/language/en-GB/en-GB.com_bar.ini</language>
<language tag="de-DE">site/language/de-DE/de-DE.com_bar.ini</language>
</languages>
Site showing whatever content is provided through the tmpl/default.php
Site shows error: 404 View not found [name, type, prefix]: foo, html, foo\component\bar\site\controller\displayView
I am running Joomla! 4.1.5 locally through XAMPP on my Windows 10 Machine.
Windows: 10.0 build 19043 (Windows 10) AMD64
PHP Version: 7.4.29
Joomla Version: 4.1.5 (fresh installation)
Database Version: 10.4.24-MariaDB
Web Server: Apache/2.4.53 (Win64) OpenSSL/1.1.1n PHP/7.4.29
I was following along this blog post. The back-end part of the component, consisting of multiple View classes and one DisplayController works perfectly fine, but not the front-end part.
After a bit of debugging of the Joomla! Controller code it seems like the view isn't fetched properly even tho its name is fetched properly. I couldn't figure out why tho.
The following error is shown in the php debug bar:
error - Uncaught Throwable of type Exception thrown with message "View not found [Name, Type, Prefix]: foo, html, foo\component\bar\site\controller\displayView".
Stack trace:
#0 [ROOT]\libraries\src\MVC\Controller\BaseController.php(646): Joomla\CMS\MVC\Controller\BaseController->getView('foo', 'html', 'foo\\component\\b...', Array)
#1 [ROOT]\components\com_bar\src\Controller\DisplayController.php(34): Joomla\CMS\MVC\Controller\BaseController->display(false, Array)
#2 [ROOT]\libraries\src\MVC\Controller\BaseController.php(735): Foo\Component\Bar\Site\Controller\DisplayController->display()
#3 [ROOT]\libraries\src\Dispatcher\ComponentDispatcher.php(146): Joomla\CMS\MVC\Controller\BaseController->execute('display')
#4 [ROOT]\libraries\src\Component\ComponentHelper.php(389): Joomla\CMS\Dispatcher\ComponentDispatcher->dispatch()
#5 [ROOT]\libraries\src\Application\SiteApplication.php(204): Joomla\CMS\Component\ComponentHelper::renderComponent('com_bar')
#6 [ROOT]\libraries\src\Application\SiteApplication.php(243): Joomla\CMS\Application\SiteApplication->dispatch()
#7 [ROOT]\libraries\src\Application\CMSApplication.php(278): Joomla\CMS\Application\SiteApplication->doExecute()
#8 [ROOT]\includes\app.php(63): Joomla\CMS\Application\CMSApplication->execute()
#9 [ROOT]\index.php(32): require_once('C:\\Apps\\xampp\\h...')
#10 {main}
Labels |
Added:
No Code Attached Yet
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-07-25 09:24:30 |
Closed_By | ⇒ | chmst |
namespace Foo\Component\Bar\Site\View\Foo;
The name of our component is com_bar, not com_foo
I used "Foo" and "Bar" as placeholders for the actual values. The components name actually is com_bar
. (I'll edit the first post accordingly)
This doesn't solve my problem though.
Where do I go to get the help with this?
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);
}
}
namespace Foo\Component\Bar\Site\View\Foo;
The name of our component is com_bar, not com_foo
this is not a Joomla issue and I close this, but you can add comments.