2

How could I get access level for a given URL?
I need to know if a URL is accessible for registered or only guests users.

  • Where do you need to know this? What are you trying to do? – FFrewin Feb 22 '15 at 9:23
6

I don't think there is info about the access on the URL level, nor there is a "global - thing" that controls the access of any url/page, so you can fetch this info in a list.

Some brief background information on ACL

*anyone please correct me if that's no correct.

Access levels occurs much lower in the system - It works on each component and its content elements.

With ACL you don't set access on URLs, rather you do it on content elements individually.

Usually the components have options to specify the access levels for their content items, which are stored in the associative items table in the database.

After requesting a page through a URL, Joomla will return the content of this page based on the url query, which usually specifies a component, a view and a content item.
Usually the component's code that is responsible to display the above content, will check the access level of the content item stored in the database and compare it with the current user's view access level, in order to decide if it will show or not the content to that user.

So, this concludes regarding to the ACL, that what you need to check, is about specific content items access levels.


Current Menu Item's Access Level

What I can think is close to what you might want, is to check the menu item's access level, since Menu Items play big role in displaying content and building URLs. But keep in mind that there can be so many situations, where a menu item could have a public access level, while the included content being in a restricted level.

In any case, if you need to check the access level for a menu item, you can go like this:

$app = JFactory::getApplication();
$menu = $app->getMenu();
$menuActive = $menu->getActive();
$menuActive->access;


Get Article Access Level by ID

For an article you can go like this:

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

*It would help to get even better answer, if you would specify from where you want to get this information and describe what you are trying to achieve.

0

From Joomla 3.8 and higher you can use Namespacing

use Joomla\CMS\MVC\Model\BaseDatabaseModel;

BaseDatabaseModel::addIncludePath(JPATH_SITE . '/components/com_content/models');
$articleModel = BaseDatabaseModel::getInstance('Article', 'ContentModel');
$article = $articleModel->getItem($articleId);
$access = $article->access;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.