-->

bypass joomla menu system

2019-09-19 05:41发布

问题:

I would love a code snippet that allowed me to intercept the URL given and then depending on a parameter serve a specific page.

The purpose would be that no matter the url if the last part of the url had say '/blah' the page I wanted would display.

ex 1: http://website/index.php/blah/
ex 2: http://website/index.php/blogcategory/articlex/blah/
ex 3: http://website/index.php/blogcategory/article5/blah/

Would all show the same article.

Thanks,

Mat

回答1:

You need a plugin that is triggered 'onAfterInitialise'. Have a look at:

http://docs.joomla.org/Plugin/Events/System#onAfterInitialise

The code you need for your function would be something like (not tested):

/**
* Do something onAfterInitialise
*/
function onAfterInitialise()
{
    // check for occurrence of string in url
    $findme = 'blah';
    $myuri = JRequest::getURI();
    $tocheck = strpos($myuri, $findme);

    if ($tocheck === true) {
        $app = JFactory::getApplication();
        $app->redirect('/anywhereyouwant'); 
    }
}


标签: joomla