joomla-cms
joomla-cms copied to clipboard
$default_view does not work in BaseController
I have an (almost empty) ArticleController extends BaseController on the site part
I use there protected $default_view = 'article';
When using the URL http:/myhost/index.php/component/nycomponent/?controller=Article&id=70
I get the error: View not found [name, type, prefix]: featured, html, site
The view featured comes from the input so my default_view is ignored
System information (as much as possible)
Opensuse PHP 8.1 Joomla 4.3.2
Additional comments
If I understand correctly, you are working on an own component?
In my experience, these errors are always caused by wrong usage of namespace, typos in filenames or wrong classnames.
You could join the extension development cannel on our mattermost https://joomlacommunity.cloud.mattermost.com. There are developers who can help you.
I close this as it is not a bug in Joomla. We can re-open if you are sure that it is a bug,
I think, this is a bug. Let me present my short example. This is a container where I get the error:
class ArticleController extends BaseController{
protected $default_view = 'article';
public function display($cachable = false, $urlparams = array()) {
return parent::display($cachable, $urlparams);
}
}
When I change it to the following - there is no error.
class ArticleController extends BaseController{
protected $default_view = 'article';
public function display($cachable = false, $urlparams = array()) {
$view = $this->input->get('view');
if($view == 'featured') {
$this->input->set('view', $this->default_view);
}
return parent::display($cachable, $urlparams);
}
}
It means (in my opinion) that there are no missing parts in my code.
What is interesting, the problem appears ONLY on the Front End. When I do is in Admin Part there is no problem.
There is nothing wrong with the code in BaseController. The real reason here is that your link does not contains Itemid variable value is ID of the menu item associated with your component. So Joomla uses Home menu item as the active and pass variables from query of that menu item to your request (The Home menu item is linked to view featured of com_content by default, that's the reason you has featured when trying to get view from input)
This routing issue is something which Joomla needs to address. However, while waiting for it to work properly, you can use that workaround code or passing right value for Itemid variable in your link.
@Hackwar pinging you as this appears to be linked to the recent work you have been doing. Perhaps you already fixed this
Indeed, this would most likely be solved by #42989. @ironbone can you check if that helps you?
Since we have #42989, I'm closing this issue.