2

I have created a view for my custom component and it works OK however I've noticed that JRoute only works for the current view.

If I am, for example, on the view picture and I try to "JRoute another view", instead of showing this view I just "JRouted to", it shows the same picture view.

Example:

 JRoute("index.php?option=com_gallery&view=thumbnails")

Instead of showing mysite.com/thumbnails it shows mysite.com/picture. The same thing happens if I am on the view thumbnail and I do a JRoute::_("index.php?option=com_gallery&view=picture") instead of showing the view picture it shows the thumbnail view which means it works only for the current view.

I have tried using the Router file that comes with Joomla (in the com_users folder) but I could not get it working for me as it extends JComponentRouterView and the custom Router file I have for my component implements JComponentRouterInterface.

I tried:

$this->registerView(new JComponentRouterInterface('thumbnails'))

and I got:

Call to undefined method GalleryRouter::registerView()

Obviously registerView doesn't exist in JComponentRouterInterface

So I would like to know if there's any way to register or add my views to my router file or something I can do in order for them to be "recognised" in all views.

I'm currently using this workaround: JURI::base()."my-menu-item"

1 Answer 1

2

You need to add your own router.php and build your own views in the build + parse methods in it. I would create a router.php file with this information: https://docs.joomla.org/J3.x:Supporting_SEF_URLs_in_your_component#A_more_complex_Example

PS: I'd recommend to use name spacing to be compatible with future Joomla versions. It's possible since Joomla 3.8 + PHP 7.x. Instead of JRoute you would use Route and add use Joomla\CMS\Router\Route; at the top of your script.

1
  • Yes I have done that. The problem is that I have been running into troubles because JRoute isn't yet very well-established. I have been running into some issues with different "JRoute documentations". But I will try again this one you recommended me as it extends RouterBase might solve my problems. The thing is that I need my custom component's url to work and I also need JRoute working for all views. I will upvote this for now. I will try that and I will accept your answer if it works. Thank you. By the way I have something similar in my Router file but it Implements instead of extending. Commented Jul 1, 2020 at 10:50

Your Answer

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

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