CakePHP 4 ACL implementation
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
- 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.
- Composer required to download Cake Framework and PHP Plugin.
- Minimum PHP 7.2 (8.0 supported).
- mbstring PHP extension
- intl PHP extension
- SimpleXML PHP extension
- 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.
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.