Adding extra views in the new Joomla router ?

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
duddy67
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 228
Joined: Sun Jul 12, 2009 12:04 pm

Adding extra views in the new Joomla router ?

Postby duddy67 » Mon Feb 05, 2018 6:23 am

Hi,

I'm trying to use the new Joomla router with my component but I'm stuck with the adding of extra views.
According to the Joomla documentation https://docs.joomla.org/J3.x:Supporting_SEF_URLs_in_your_component I first set up my router's constructor like this:

Code: Select all

...
$categories = new JComponentRouterViewconfiguration('categories');
$categories->setKey('id');
$this->registerView($categories);
$category = new JComponentRouterViewconfiguration('category');
$category->setKey('id')->setParent($categories, 'catid')->setNestable()->addLayout('blog');
$this->registerView($category);
// The view for the item of my component.
$note = new JComponentRouterViewconfiguration('note');
$note->setKey('id')->setParent($category, 'catid');
$this->registerView($note);
...

So far so good, the new router works fine with my component and the url query segments are properly built and parsed.
But, the problem is that my component has also 2 extra views (tags and tag) which also have the component item (note) as children.

Code: Select all

...
$tags = new JComponentRouterViewconfiguration('tags');
$tags->setKey('id');
$this->registerView($tags);
$tag = new JComponentRouterViewconfiguration('tag');
$tag->setKey('id')->setParent($tags, 'tag_id')->setNestable()->addLayout('blog');
$this->registerView($tag);
// The view for the item of my component.
$note = new JComponentRouterViewconfiguration('note');
$note->setKey('id')->setParent($tag, 'tag_id');
$this->registerView($note);
...

Things become tricky now as it seems not possible to register all the views (categories, category, tags and tag) at the same time in the constructor (I tried and experienced some application crashes). Moreover my component item now ends up with 2 different parents which looks a bit weird.

One solution would be to register the router's views on the fly according to the view contained in the current url query, but unfortunatly I couldn't get it from the router's constructor.
The other solution would be to register the router's views from another location where I can retrieve the current view. But is it possible ?

May be is there another way to get it work ?

Any help or information would be very much appreciated.

Return to “Joomla! 3.x Coding”

Who is online

Users browsing this forum: Webdongle and 6 guests