1

I am writing a component for site side and having some troubles with router. I have 2 views in one component, both them have only one default.php template and default.xml to define menu type for each view (for ex. let's call them views (1) and (2) ). It is also SEF turned on at site.

So, first view (1) is url-independant: it only shows some text info.

Second view (2) also shows some data from DB; It can pass user to itself with new parameter (for ex. &cityid=5 ) to show the data of some other kind (the same DB query, but with extra filters, in our case, e.g. '... WHERE (...) AND cityid="5"').

I have two page (menu items) on site with first (1) and second (2) views respectively.

But when I started to write the Router.php, I found that [component]BuildRoute(&$query) function's parameter $query doesn't contain $query['view'] member. It contains 'option' and 'Itemid', but there is no 'view' member, so I can't pass it to function's result (therefore, there is the same situation with [component]ParseRoute: it won't recieve the 'view' parameter, so I can't pass it to Joomla it to display correct view (first (1) or second (2))). So, if we would forget about the 'view' parameter, Joomla displays the default view, which is first (1) view in my case, but I need it to be the second (2) view (look above).

P.S. The fact is that JRequest::getVar('view') returns correct value, but it is not passed in $query array.

P.S. May be I am doing something totaly wrong, 'cause I am new to Joomla. Then, please, help me to realize the model I described in top.

Thx in advance.

1 Answer 1

1

BuildRoute function gets whatever the information you will pass to it. How you are creating your urls in your component? Like this?

$url = JRoute::_('index.php?option=com_mycomponent&view=myview&task=mytask&id=1');

In above case the view parameter is passed with the url structure and hence the BuildRoute function knows how to get the view parameter. If you do not pass view paramter, it won't get it.

If it is accessed using menu item, check what is the link value of your menu item.

On the other hand, ParseRoute function gets its values from the sef url. For example:

url: mywebsite.com/someslug/someother/1-idone.html

The above url has 3 parameters, someslug, someother and 1-idone. So it is upto you how do you parse them in your ParseRoute function. i.e. view/task/id or task/view/id or whatever the order that your component is generating them with BuildRoute function.

The above url structure is just an example and not baseline. It is completely upto you how you build your route and parse in opposite way.

Some suggestions if you are using Joomla 3 or above.

  1. Do not use JRequest::getVar, instead use JFactory::getApplication()->input->get functions.

Your Answer

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

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