Adding extra views in the new Joomla router ?

35 views
Skip to first unread message

Lucas Sanner

unread,
Feb 5, 2018, 7:31:04 AM2/5/18
to Joomla! General Development
Hi all,

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 I first set up my router's constructor like this:

...
$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. 

...
$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 where and is it possible ?

May be is there another way to get it work ?

Any help or information would be very much appreciated.

Hannes Papenberg

unread,
Feb 5, 2018, 7:41:18 AM2/5/18
to joomla-de...@googlegroups.com
Hello Lucas,
you can not register one view twice in the router. Simply because that
would mean that there are 2 ways to reach the view and that would mean
that the URLs would not be unique. You would effectively create
duplicate content. I think what you want, is to simply not register the
note view for the tag view.

Hannes

Am 05.02.2018 um 13:15 schrieb Lucas Sanner:
> Hi all,
>
> 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 I first set up my router's
> constructor like this:
>
> |
> ...
> $categories =newJComponentRouterViewconfiguration('categories');
> $categories->setKey('id');
> $this->registerView($categories);
> $category =newJComponentRouterViewconfiguration('category');
> $category->setKey('id')->setParent($categories,'catid')->setNestable()->addLayout('blog');
> $this->registerView($category);
> // The view for the item of my component.
> $note =newJComponentRouterViewconfiguration('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.
>
> |
> ...
> $tags =newJComponentRouterViewconfiguration('tags');
> $tags->setKey('id');
> $this->registerView($tags);
> $tag =newJComponentRouterViewconfiguration('tag');
> $tag->setKey('id')->setParent($tags,'tag_id')->setNestable()->addLayout('blog');
> $this->registerView($tag);
> // The view for the item of my component.
> $note =newJComponentRouterViewconfiguration('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 where and is it
> possible ?
>
> May be is there another way to get it work ?
>
> Any help or information would be very much appreciated.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! General Development" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to joomla-dev-gene...@googlegroups.com
> <mailto:joomla-dev-gene...@googlegroups.com>.
> To post to this group, send email to joomla-de...@googlegroups.com
> <mailto:joomla-de...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/joomla-dev-general.
> For more options, visit https://groups.google.com/d/optout.

Lucas Sanner

unread,
Feb 7, 2018, 7:43:06 AM2/7/18
to Joomla! General Development
Hello Hannes and thanks for your reply.

After many tests it seems impossible to register the 2 views (tag and category) and not register the 
note view for the tag view as you suggest. 

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

The application crashes depending on the selected view. 
So it seems like I have to choose between the category or tag view but not both. 
However I'm very confused with the view registrations. For instance I don't get why the code above make the application crash since there is no conflict between the views.




Reply all
Reply to author
Forward
0 new messages