如何获取Joomla 2.5中当前内容(文章)的访问级别
使用Joomla API为活动请求呈现的当前内容(文章)获取访问级别的推荐方法是什么 目前,我已经使用手动查询对其进行了黑客攻击,但我认为应该有一种方法可以使用对象模型获得访问级别,而不必编写自定义查询,这感觉不太对如何获取Joomla 2.5中当前内容(文章)的访问级别,joomla,Joomla,使用Joomla API为活动请求呈现的当前内容(文章)获取访问级别的推荐方法是什么 目前,我已经使用手动查询对其进行了黑客攻击,但我认为应该有一种方法可以使用对象模型获得访问级别,而不必编写自定义查询,这感觉不太对 $db = JFactory::getDBO(); $cid = JRequest::getInt('id', 0); // get the content id from the request $query = ' SELECT #__content.access F
$db = JFactory::getDBO();
$cid = JRequest::getInt('id', 0); // get the content id from the request
$query = ' SELECT #__content.access FROM #__content WHERE #__content.id="'.$cid.'"';
$db->setQuery($query);
$objList = $db->loadObjectList();
foreach($objList as $obj)
{
return $obj->access; // gets the access level for the first object
}
您可以调用下面文件中文章模型中定义的getItem函数:
components\com\u content\models\article.php
您需要首先加载模型并通过传递项目id调用getItem函数
jimport('joomla.application.component.model');
JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_content/models');
$articleModel = JModelLegacy::getInstance( 'Article', 'ContentModel' );
调用函数:
$result = $articleModel->getItem($articleId);
并使用访问级别:
$result->access;
我注意到你用了JModelLegacy。Joomla 3 API是否有任何相应的惯用功能?在Joomla 3.8中,您可以使用BaseDatabaseModel+名称间距,请参见: