3

For reasons beyond the scope of the question, I want to be able to effectively (but not actually do a redirect based on various parameters.

If the request IS index.php?option=com_something&view=default

I want Joomla to display index.php?option=com_alternate&view=override as if (in every respect) that was the original request to begin with.

Can a system plugin accomplish this? And if so, on which event?

EDIT For clarity of requirement, this sample pseudo-ish code programmatically demonstrates what I'm envisioning. Before spending hours or days, I'm "checking the premises" of my intended approach.

// Effective Redirect to com_content (as an example component) without classic redirecting
class plgSystemMySystemPlugin extends JPlugin
{
    public function on[Before|After][SOME-SYSTEM-EVENT]() {
        jimport('joomla.application.component.view');
        $options = array(
            'name' => 'article',
            'base_path' => JPATH_SITE.'/components/com_content'
        );
        $view = new JView($options);
        $view->addTemplatePath(JPATH_THEMES . '/' . JFactory::getApplication()->getTemplate() . '/html/com_content/' . $view->getName());
        // Set Item, Itemid, etc. somehow here
        $view->display();
        JFactory::getApplication()->close();
    }
}  
  • I’m not sure I understood your purpose clearly. There are two places where you can manipulate routing: at Input(request) and at Router(before Response). Both have events on which your system plugin can act upon and change the values which are then forwarded for having the needed response of Joomla(display) or have a redirect. Please clarify this a bit more. (I like the Words of wisdom a lot in your profile! :) ) – Zollie Apr 19 at 5:47
  • The purpose is 400+ page document I was handed, the requirement is as I tried to explain in the question...basically an "auto correct" of the url, with NO sign of redirection in the URL OR response code. Words of wisdom? -- Thesis for my PhD from the School of Hard Knocks, lol. – GDP Apr 19 at 13:28
  • Thank you for the additional info. I think I start to understand what your intended result is. The requested URL should stay the same and the displayed page should be 'something else' (like a document), so no classical redirection. And the called component is not yours, so you cannot/do not want to edit the views of that component directly. It's a good question. At least something to think about. In system plugin the onAfterRender or onBeforeRender event is coming to my mind regarding this question suddenly. – Zollie Apr 19 at 15:21
  • At this point you can do a lot, but the big question is how to invoke another component’s view( or rendered document) instead of the given document object here, without redirect. Good question... – Zollie Apr 19 at 16:12
  • @mickmackusa Thanks for your comment, :) I'm NOT asking for coding support, I'm asking if this is something that a system plugin can/should do. The requirement is broad, beyond explaining in a SE question, and there are no specific extensions. As one of the first 5 members of this site, I'm very aware of due diligence, thus the question is "Can I", not "How Do I" – GDP Apr 21 at 13:57
3

The currently accepted solution is overcomplicated and bound to cause problems. Don't mess with fundamentals, like the URL and PHP superglobals when all you want to do is modify Joomla's routing results. That's what the onAfterRoute event is for.

Create a system plugin. Create a public function onAfterRoute. In there, get $input = JFactory::getApplication()->input. It is populated with the parsed request. If option and view and whatnot matches your criteria you can change it with $input->set('option', 'com_alternate') etc.

This solution also works with SEF URLs since it runs after Joomla has parsed the SEF URL. It does not mess with the displayed URL. It only changes how Joomla understands the URL, i.e. the routing.

  • You are right nikosdion. I think I was mislead by the "after" in "onAfterRoute" thinking the routing already had occurred. – Wieger Apr 29 at 6:44
  • I think the terms "route" and "dispatch" are more confusing than before / after in this context :) Routing is when the application is parsing the URL into something standardised and machine-friendly. Dispatching is when the application relegates control to a component. The next step is rendering, which assembles the response and sends it to the server's output. So, yes, onAfterRoute fires after Joomla finishes routing on its own but before it dispatches the application. Since the OP needs a way to "fool" dispatching that is the best place to add your code :) – nikosdion Apr 30 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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