Problems with JRoute::_()

44 views
Skip to first unread message

Mik Urrey

unread,
Mar 16, 2013, 9:59:31 AM3/16/13
to joomla-de...@googlegroups.com
Hi.
I have follow problem in my component.
I made link into a module: JRoute::_('index.php?option=com_mycomponent&view=orders&layout=cart').
It's behavior is strange: when I open a page of the component which has Itemid (e.g. /profile/myorders or /test) the link changes to /profile/myorders?view=orders&layout=cart or to /test?view=orders&layout=cart instead of /component/mycomponent/?view=orders&layout=cart on pages of other components.
Why? This is a Joomla bug? Router.php is not created now but I do not think it can cause this problem.

Mik Urrey

unread,
Mar 16, 2013, 10:03:42 AM3/16/13
to joomla-de...@googlegroups.com
P.S.: And when I try to create menu item for this page (e. g. /cart), this link does not change and problem remains.

Donald Gilbert

unread,
Mar 16, 2013, 10:30:58 AM3/16/13
to joomla-de...@googlegroups.com
If an Itemid is preset in the JRoute'd url, then Joomla believes you are attempting to map a view from your component to an existing menu item. So it does what it can with the sef url's and then it appends whatever query vars it knows what to do with. It discovers what to do via the router.php file in your component. Take a look at the com_banners/router.php for an example on how to build that. Also, to get the option to create a "My Component Orders" link when adding a new menu item, you'll need to add a com_mycomponent/view/viewname/tmpl/layoutname.xml. This xml file contains data needed by Joomla to be able to assign your component view to a menu item. This file can also get really complicated with all it's options available. To see a fullblown file with all it's options, take a look at com_content/views/categories/tmpl/default.xml. However, they bare minimum to assign your view to a menu item is:

<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="My Component Viewname">
<message>
<![CDATA[Description]]>
</message>
</layout>
</metadata>

This will allow you to create the specific Itemid for the view that you want to use.

So, what you're experiencing is expected behavior. Joomla tries to do the best it can with the info it has. The more info you give it (a router.php or a layoutname.xml) the better and more consistent it will be.


On Sat, Mar 16, 2013 at 9:03 AM, Mik Urrey <mikb...@gmail.com> wrote:
P.S.: And when I try to create menu item for this page (e. g. /cart), this link does not change and problem remains.

--
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.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mik Urrey

unread,
Mar 16, 2013, 10:57:19 AM3/16/13
to joomla-de...@googlegroups.com
Yes, cart.xml is already created in views/orders/tmpl, menu item attached to this link but it don't tesolve this problem. An alias just not works in JRoute::_.

Donald Gilbert

unread,
Mar 16, 2013, 11:12:18 AM3/16/13
to joomla-de...@googlegroups.com
Ok, so, in the module where you need to link, just pass in JRoute::_('index.php?Itemid=' . $yourAlreadyCreatedItemID);

Mik Urrey

unread,
Mar 16, 2013, 11:39:08 AM3/16/13
to joomla-de...@googlegroups.com
It works but it's bad method... Why in many cases option&view&layout links always works fine before but not here?

Don

unread,
Mar 16, 2013, 12:02:52 PM3/16/13
to joomla-de...@googlegroups.com
You'll need to put a lot of extra work into the router for your component to handle the Itemid auto discovery. It's possible, I've done it before. If I were at my computer I could send you more info on it. 

Sent from my iPhone

On Mar 16, 2013, at 10:39 AM, Mik Urrey <mikb...@gmail.com> wrote:

It works but it's bad method... Why in many cases option&view&layout links always works fine before but not here?

--

Mik Urrey

unread,
Mar 16, 2013, 12:16:51 PM3/16/13
to joomla-de...@googlegroups.com
Thank You for the hint! It's like in com_content\router.php ?

Don

unread,
Mar 16, 2013, 12:30:55 PM3/16/13
to joomla-de...@googlegroups.com
I think so. One of the core components does some auto discovery of the Itemid by checking the database. It might be in com_content. Can't remember for sure. 

Sent from my iPhone

Mik Urrey

unread,
Mar 16, 2013, 12:41:36 PM3/16/13
to joomla-de...@googlegroups.com
Ok, I will try to make it with examples from com_content and com_users.
Thank You once more :)
Reply all
Reply to author
Forward
0 new messages