简体   繁体   English

获取当前控制器joomla

[英]Get the current controller joomla

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 . 我正在joomla 3.2中开发一个网站,我在多个视图中具有相同的研究栏,并做了一些小的更改,因此我在一个独立的php文件中创建了它,并且在不同的页面中使用了它。 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 我想做的是根据当前处于活动状态的控制器更改一些次要信息,我尝试$ _SERVER ['REQUEST_URI']正常工作,但这里的代码似乎有些混乱

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 我在joomla文档中找不到类似的内容

JFactory::getApplication()->input->get('controller'); JFactory :: getApplication() - >输入 - > GET( '控制器'); As simple as that 就如此容易

For me, JFactory::getApplication()->input->get('controller') returns nothing. 对我来说, JFactory::getApplication()->input->get('controller')返回任何内容。 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. 根据出色的Joomla架构,尽管会返回单例控制器实例,但将忽略getInstance参数,尽管它会被忽略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM