Reputation: 369
I am developping a site in joomla 3.2, i have the same research bar in multiples views with some minor changes, so i created it in an independent php file and i'm using it in different pages . What i want to do is to change some minor informations depending on which controller is currently active I tried $_SERVER['REQUEST_URI'] it works fine but it seems a little messy here is my code
function startsWith($haystack, $needle) {
echo $needle;
echo $haystack;
return $needle === "" || strpos($haystack, $needle) === 0;
}
then i test like this
<?php if (startsWith($_SERVER['REQUEST_URI'], "/Immo/administrator/index.php? option=com_xxo&controller=yy")) { show something ...}
is there a better way to know what controller is active for the current page ? I did not find something similar in the joomla doc
Upvotes: 1
Views: 1747
Reputation: 462
For me, JFactory::getApplication()->input->get('controller')
returns nothing. This is how I do it:
$controller = \JControllerLegacy::getInstance('whatever');
As per fabulous Joomla architecture, you cannot omit getInstance parameter although it is ignored because singleton controller instance is returned.
Upvotes: 0
Reputation: 36
JFactory::getApplication()->input->get('controller'); As simple as that
Upvotes: 2