How to automatize CakePHP’s ACL database creation
If you use CakePHP framework, maybe you want to use its built-in user authentication and access list control. It can be really easy managed from Cake’s console application or You can use prepared scripts in application’s config directory. But sometimes console won’t work and you can’t use included SQL statements – for example if you use PostgresSQL as I do. If you don’t want to change prepared DB scripts, you can use included database schema to create tables requested by DB ACL component. Here is example code for this:
<?php class AppController extends Controller { var $components = array('Auth', 'Acl'); var $uses = array('users'); public function beforeFilter() { /* Create ACL*/ require_once(CAKE . '/libs/model/schema.php'); require_once(APP . '/config/sql/db_acl.php'); $oSchema = new DbAclSchema(); $oDB =& $this->users->getDataSource(); $aTable = array(); foreach ($oSchema->tables as $aTable => $fields) { $oDB->execute($oDB->dropSchema($oSchema, $aTable)); $oDB->execute($oDB->createSchema($oSchema, $aTable)); } /* END create ACL */ } } ?>
After you have created tables, just delete code from AppController.



Grafika by Števo Bačkor