PHP
Joomla! 6
Joomla! 5
Joomla! 3 (Legacy)
Component
Intermediate
Check Granular ACL Permissions with $user->authorise()
Validates core.create, core.edit, core.edit.own and core.delete permissions at component, category or item asset level.
components/com_example/src/Controller/ItemController.php
<?php
declare(strict_types=1);
use Joomla\CMS\Factory;
$user = Factory::getApplication()->getIdentity();
$asset = 'com_content.article.' . (int) $item->id;
$canEdit = $user->authorise('core.edit', $asset)
|| ($user->authorise('core.edit.own', $asset) && (int) $item->created_by === (int) $user->id);
if (!$canEdit) {
throw new \RuntimeException('Acesso negado', 403);
}
Supports core.edit.own by verifying created_by matches the active identity.
components/com_example/src/Controller/ItemController.php
<?php
$user = JFactory::getUser();
$canEdit = $user->authorise('core.edit', 'com_content.article.' . (int) $item->id);
Legacy Joomla 3 ACL check via JFactory::getUser().
Technical explanation and best practices
Never hardcode usergroup IDs to gate features. Always check Joomla ACL rules with $user->authorise($action, $asset) so custom roles and inheritance work as configured.