检索Joomla 2.5组件项ID

时间:2012-08-06 06:47:29

标签: joomla

我正在开发一个组件,我想检索项目ID并使用该ID,这样每次页面加载该项目ID都将用于其他事情。 感谢

2 个答案:

答案 0 :(得分:1)

要检索组件项的ID,您需要执行以下操作:

使用它的ID创建项目的链接,例如

$mylink = 'index.php?option=com_yourcomponent&view=myitemview&id=99'

然后,如果用户启用了SEF,您应该通过JRoute传递该链接:

$myRoutedLink = JRoute::_($myLink);

这可确保您在构建商品页面时尝试访问ID时可以使用。对于Joomla! 2.5你应该使用JInput来检索变量,因为自{J }.7以来JRequest已被折旧和替换。

第一步是获得Joomla!实例,然后在检索变量之前输入对象,例如

// Get Joomla! instance
$jAp = JFactory::getApplication();
$jInput = $jAp->input;

现在我们可以得到你的变量:

// Get variables
$passedID = $jInput->get('id',0) // Where the 0 is the default if 'ID' doesn't exist.
$passedInt = $jInput->getInt('myInt',0) // You can also get JInput to give the right type back

答案 1 :(得分:0)

我知道joomla 1.5.xx

我已经习惯从网址获取itemid:

$itemid = JRequest::getVar('itemid');

希望这对你也有帮助。请点击此链接获取更多信息JRequest