Adding ACL rules to your component

From Joomla! Documentation

Revision as of 00:54, 5 December 2011 by Mrs.siam (Talk | contribs)

This tutorial will demonstrate how to add custom action permission to your component down to object level. Normally we familiar with ACL in global configuration level, category level and component level. Now we will learn how to add action permission control in our component.

JTable Support

JTable class has some built-in support for ACL, to use this you have to add one integer field in your table named 'asset_id'. This field will be used to control action control for your object. Do not confuse with 'access', that is only for access permission (read side) as Joomla! separates other actions from read acess.

Normally, we have to override __construct() method in our descendant class. We may also override check() method to validate our data before saving to database. For ACL action support we have to override these methods:-

  • public function bind($array, $ignore = ) to let JTable save rule data to Joomla's assets table.
  • protected function _getAssetName() to give asset name for our asset.
  • protected function _getAssetParentId($table = null, $id = null) to give parent id of our asset, normally Joomla! uses root (1) as a parent. Generally we will change this to our component.

JTable Example

class AstermanTableUnit extends JTable
	public function __construct($db)
		parent::__construct('#__asterman_units', 'id', $db);
	public function bind($array, $ignore = '')
		// Bind the rules. 
		if (isset($array['rules']) && is_array($array['rules'])) { 
			$rules = new JRules($array['rules']); 
		return parent::bind($array, $ignore);
	 * Redefined asset name, as we support action control
        protected function _getAssetName() {
		$k = $this->_tbl_key;
		return 'com_asterman.unit.'.(int) $this->$k;
         * We provide our global ACL as parent
     	 * @see JTable::_getAssetParentId()
	protected function _getAssetParentId($table = null, $id = null)
		$asset = JTable::getInstance('Asset');
		return $asset->id;

Model Support

Form Support