Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$default_view does not work in BaseController #40991

Closed
ironbone opened this issue Jun 20, 2023 · 6 comments
Closed

$default_view does not work in BaseController #40991

ironbone opened this issue Jun 20, 2023 · 6 comments

Comments

@ironbone
Copy link

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

@chmst
Copy link
Contributor

chmst commented Jun 20, 2023

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,

@chmst chmst closed this as completed Jun 20, 2023
@ironbone
Copy link
Author

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.

@chmst chmst reopened this Jun 21, 2023
@joomdonation
Copy link
Contributor

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.

@brianteeman
Copy link
Contributor

@Hackwar pinging you as this appears to be linked to the recent work you have been doing. Perhaps you already fixed this

@Hackwar
Copy link
Member

Hackwar commented Mar 24, 2024

Indeed, this would most likely be solved by #42989. @ironbone can you check if that helps you?

@Hackwar
Copy link
Member

Hackwar commented Mar 30, 2024

Since we have #42989, I'm closing this issue.

@Hackwar Hackwar closed this as completed Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants