How to get access level for current content (article) in Joomla 2.5

StackOverflow https://stackoverflow.com/questions/23399709

  •  13-07-2023
  •  | 
  •  

سؤال

What is the recommended way to get the access level for the current content (article) being rendered for the active request, using the Joomla API.

Currently I've got it hacked using a manual query but this doesn't feel right in that I assume that there should be a way to get the access level using the object model, and not by having to write a custom query.

$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
}
هل كانت مفيدة؟

المحلول

You can call getItem function defined in model of article in below file:

components\com_content\models\article.php

You need to load the model first and call the getItem function by passing article id.

jimport('joomla.application.component.model');
JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_content/models');
$articleModel = JModelLegacy::getInstance( 'Article', 'ContentModel' );

Call the function:

$result = $articleModel->getItem($articleId);

And use the access level:

$result->access;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top