CakePHP

CakePHP ACL Behavior modified

Posted in CakePHP, Development on February 28th, 2008 by Steve – Be the first to comment

I’ve posted this up at the bakery, but articles seem to take awhile to get published. It could also be that they’re working on a new ACL Behavior, one can hope. For the time being, I’ve fixed up the core behavior and added a few features as well. I’ll just replicate here what I wrote at the bakery.

This Acl behavior makes a number of improvements from the built-in one. It allows you to have a model act as both an “Aro” and “Aco”. It creates an alias in this format “Model.id”. If parent node is not provided, it’ll create one based on root object. For example, if you create Post.1 as an ACO and you set parentNode to null, it’ll set the parent_id to the root “Post” Aco if it exists. So your tree would look like the following:

Acos
----------
Post
|-Post.1
|-Post.2
|-Post.3

Usage Instructions

Follow the following steps to use the Acl behavior.

Step 1

Copy the behavior class into a file named “acl.php” in your /app/models/behaviors folder.

Step 2

Load the behavior in the model you want to use it in.

Examples:

Ex 1: Act as Aco

var $actsAs = array('Acl' => array('Aco'));

Ex 2: Act as Aco

var $actsAs = array('Acl' => 'Aco');

Ex 3: Act as Aro

var $actsAs = array('Acl' => array('Aro'));

Ex 4: Act as Aro and Aco

var $actsAs = array('Acl' => array('Aro', 'Aco'));

Step 3

Create the method parentNode($type) in your model. This will return the parent_id to a method in the Acl behavior.

Here’s an example of a User model passing a group id as it’s parent id only for the ARO:

function parentNode($type)
{
if ($type == 'Aro') {
if (!$this->id) {
return null;
}
 
$data = $this->read();
 
if (!$data['User']['group_id']){
return null;
} else {
return array('model' => 'Group', 'foreign_key' => $data['User']['group_id']);
}
} else {
return false;
}
}

That’s it!
Download the behavior class here

CakePHP gives us xmas present :)

Posted in CakePHP, Development on December 29th, 2006 by Steve – Be the first to comment

First and foremost, happy holidays everyone. T’is the season of giving and that’s just what CakePHP has done. On christmas day, CakePHP has released version 1.2.0.4206_dev and what a release it was! Although I have to try out these new promised features, I really like what the cake team has done. They have addressed some requests for the framework by putting in commonly used components into the cake core.

- A better validations class

- Improvements to the Form helper

- Pagination! Finally :)

- An email component

- Support for HTTP Auth

And a few other changes were made as well. While there are already existing components for paginaton, email, etc, made by the cake community, it’s good to see these cake supported components. They are such common components that I’d say most applications would rely on them and it’s good to have a framework with these features built-in.

Check out their official announcement at the cakephp website.

Have a happy new year everyone! I look forward to see the stable version of 1.2 in the new year

Why choose CakePHP

Posted in CakePHP, Development on December 15th, 2006 by Steve – Be the first to comment

Here’s a pretty good article that Christine Anderssen of webpronews.com wrote on choosing cakePHP framework over other frameworks available out there.

The point is, the web developer is now really spoilt for choice. Which is a problem in itself, since having too much choice can leave you dithering between different options. This article is therefore about how I made my choice, which was CakePHP, and which factors I took into consideration.

Read the full article here.

Try out CakePHP

Posted in CakePHP, Development on December 13th, 2006 by Steve – Be the first to comment

CakePHP LogoA few months ago I decided to take my php programming to a whole new level and try a framework. There were a few that captured my interest. Symfony, Code Igniter, and CakePHP. I experimented with all 3. I really liked Code Igniter and CakePHP. Code Igniter seems to be very well documented which I felt CakePHP lacked, however, recently CakePHP has come out with The Bakery. This has helped create a more organized way for the community to contribute documentation, tutorials, etc to this framework.

I started getting more comfortable with CakePHP and have decided to make it my framework of choice. It seems to be coming along very well and the development team are extremely active in the usenet groups and IRC channel.

I wrote a very simple authentication component for the project along with a tutorial on how to use it. So if you decide to try out CakePHP for your next project and are looking for simple authentication, try it out.

You can get the component here: http://bakery.cakephp.org/articles/view/130
The tutorial can be viewed here: http://bakery.cakephp.org/articles/view/121