[英]Joomla 2.5: how to add a custom query to global db object?
I am upgrading a website from 1.5 to 2.5 which is used by different clients. 我正在将网站从1.5升级到2.5,以供不同的客户使用。 To make sure to display the correct menues and modules I need to make a custom query in a system plugin when loading the page.
为了确保显示正确的菜单和模块,我需要在加载页面时在系统插件中进行自定义查询。
How can I set my query to the global dbo? 如何将查询设置为全局dbo? I need to add a few lines so that the query also gets in the standard query in menu.php for example.
我需要添加几行,以便查询也可以进入例如menu.php中的标准查询。
Here is my code: 这是我的代码:
$db = JFactory::getDbo();
$query = $db->getQuery();
$query->leftJoin("#__menu_types AS mt ON m.menutype = mt.menutype");
$query->leftJoin("#__wl_clientmap as cm on cm.target_id=mt.id AND cm.target_type='mnu'");
if ($this->clientid>0){
$query->where("cm.client_id=".intval($this->clientid)."");
}
else {
$query->where("(cm.client_id=0 OR cm.client_id IS NULL)");
}
$db->setQuery($query);
$menu = & JSite::getMenu();
and here is what's in includes/menu.php: 这是include / menu.php中的内容:
public function load()
{
// Initialise variables.
$db = JFactory::getDbo();
$app = JApplication::getInstance('site');
$query = $db->getQuery(true);
$query->select('m.id, m.menutype, m.title, m.alias, m.note, m.path AS route, m.link, m.type, m.level, m.language');
$query->select('m.browserNav, m.access, m.params, m.home, m.img, m.template_style_id, m.component_id, m.parent_id');
$query->select('e.element as component');
$query->from('#__menu AS m');
$query->leftJoin('#__extensions AS e ON m.component_id = e.extension_id');
$query->where('m.published = 1');
$query->where('m.parent_id > 0');
$query->where('m.client_id = 0');
$query->order('m.lft');
Sadly my custom query does not appear on menu.php's query. 可惜我的自定义查询没有出现在menu.php的查询中。 How can I make sure that it gets in?
我如何确保它进入?
You can hijack the database object the same way Joomfish does, roughly it works like this in a system plugin 您可以像Joomfish一样劫持数据库对象,在系统插件中大致如此
$db = & JFactory::getDBO();
$db = new JFDatabase($options);
Then all queries go through your object and you can pass anything you don't want to change on to the normal database layer. 然后,所有查询都将遍历您的对象,并且您可以将任何您不想更改的内容传递给普通数据库层。
Have a look at jfrouter plugin in Joomfish to get some more ideas. 看看Joomfish中的jfrouter插件,以获得更多的想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.