From Joomla! Documentation

< API16:JAccess
Revision as of 16:34, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.


Method to return the JRules object for an asset. The returned object can optionally hold only the rules explicitly set for the asset or the summation of all inherited rules from parent assets and explicit rules.

[Edit Descripton]



static getAssetRules($asset, $recursive=false)
Parameter Name Default Value Description
$asset Integer asset id or the name of the asset as a string.
$recursive false True to return the rules object with inherited rules.


object object for the asset.

Defined in



jimport( 'joomla.access.access' );

Source Body

public static function getAssetRules($asset, $recursive = false)
        // Get the database connection object.
        $db = JFactory::getDbo();
        // Build the database query to get the rules for the asset.
        $query  = $db->getQuery(true);
        $query->select($recursive ? 'b.rules' : 'a.rules');
        $query->from('#__assets AS a');
        $query->group($recursive ? '' : '');
        // If the asset identifier is numeric assume it is a primary key, else lookup by name.
        if (is_numeric($asset)) {
                // Get the root even if the asset is not found
                $query->where('( = '.(int) $asset.($recursive ? ' OR a.parent_id=0':'').')');
        } else {
                // Get the root even if the asset is not found
                $query->where('( = '.$db->quote($asset).($recursive ? ' OR a.parent_id=0':'').')');
        // If we want the rules cascading up to the global asset node we need a self-join.
        if ($recursive) {
                $query->leftJoin('#__assets AS b ON b.lft <= a.lft AND b.rgt >= a.rgt');
        // Execute the query and load the rules from the result.
        $result = $db->loadResultArray();
        // Instantiate and return the JRules object for the asset rules.
        $rules  = new JRules;
        return $rules;

[Edit See Also] SeeAlso:JAccess/getAssetRules


<CodeExamplesForm />