CakePHP 4 ACL implementation

Aneh Thakur
TrinityTuts
Published in
2 min readApr 26, 2021

CakePHP is a free open-source framework just like Larvel. CakePHP follows Model View Controller (MVC) approach. You can create your applications simpler, faster, and require less code.

Prerequisites

  1. HTTP Server. For example Apache. Having mod_rewrite is preferred, but by no means required. You can also use Nginx, or Microsoft IIS if you prefer.
  2. Composer required to download Cake Framework and PHP Plugin.
  3. Minimum PHP 7.2 (8.0 supported).
  4. mbstring PHP extension
  5. intl PHP extension
  6. SimpleXML PHP extension
  7. PDO PHP extension

Step 1. Now install and create a new project using composer.

composer create-project --prefer-dist cakephp/app:~4.0 my_new_app

Step 2. Once a new project created we need to install the CakePHP Acl plugin using the below command.

composer require cakephp/acl

Step 3. If the plugin installed successfully we need to load the plugin in the Application.php file. You can load the plugin using the below command.

bin/cake plugin load acl

You can also manually load the plugin inside the src/Application.php file inside the bootstrap() method.

CakePHP 4 Acl implementation Tutorial Trinitytus
public function bootstrap(): void
{
$this->addPlugin('Acl');
/*.. Other Code...*/
}

Step 4. Create a database in phpMyAdmin and add database details in config/app_local.php. Find Datasources array and add your details.

Step 5. Now create the required ACL table by running the below command.

bin/cake migrations migrate -p Acl

You can continue these steps on TrinityTuts.com.

--

--