CakePHP Articles & Posts

How to Create your own Scaffolding plugin for CakePHP 2

CakePHP’s builtin scaffolding is great but sometimes I wish it would do more or behave a little differently. Until recently, I assumed this couldn’t be accomplished with the way scaffolding was baked in. Thanks to the clever way CakePHP handles includes, we can easily use our own scaffolding implementation by adding 2 lines to AppController.

In this tutorial we will built a scaffolding plugin that is aware of the TreeBehavior (continue reading…)


  • pronique com
  • cakephp generate list scaffolding
  • cakephp 2 1 tutorial
  • throughf7z

CsvExport Behavior for CakePHP 2

This behavior is the exact opposite of the CsvImport behavior included in the Utils plugin from CakeDC. This Behavior will end on github but for now, here is the source code and instructions on how to use the Behavior. (continue reading…)


  • cakephp csv

Enable CSV Import for all controllers/models in a CakePHP 2.x project

CakePHP LogoI often use phpMyAdmin to import csv data into projects I am building, this can be tedious as phpMyAdmin requires the number of fields and field order to match exactly for the csv import to work.

This frustration prompted me to explore the (continue reading…)


  • cakephp csv import
  • cakephp import csv

[CakePHP] Modeling a simple accounting system with estimates, invoices, and payments.

Database tables and Model classes are where most CakePHP applications begin. With this example, we will focus on Model associations rather than providing a complete tutorial of an application. Consider this a solid foundation for building an Accounting Web App, this is the M in MVC.

The idea behind what we are modeling today is a simple accounting web app similar to Freshbooks or something QuickBooks offers. The model definitions and relationships are as follows. (continue reading…)


  • cakephp accounting system
  • cakephp invoice
  • invoice program in cakephp

Installing CakePHP 2.1 with git clone

If you have ssh shell access to you web server installing CakePHP very simple using git.
First, determine if you have git installed. (continue reading…)


  • git cakephp


cakecore is a command line tool and convention for installing/updating the CakePHP core libraries in /usr/lib/cakephp. Using cakecore provides a foundation for maintaining one core, for many apps. The advantages are…

  • One copy of each major version of the CakePHP core libraries.
  • Easy upgrade when new CakePHP version are released.
  • Switch to newer version of CakePHP on a per project basis.
  • Reduce disk space required for each project.
  • Decoupling the core libraries means less to commit and maintain in code repositories.

Installing CakeCore

# clone cakecore from github
sudo git clone /usr/lib/cakephp

# add cakecore to your path
sudo ln -s /usr/lib/cakephp/cakecore /usr/bin/cakecore

Checkout and install CakePHP

sudo cakecore install-all
# Installs a copy of each major version of CakePHP in...
# /usr/lib/cakephp/1.2/
# /usr/lib/cakephp/1.3/
# /usr/lib/cakephp/2.0/
# /usr/lib/cakephp/2.1/

Updating CakePHP

sudo cakecore update-all

Check current CakePHP versions

sudo cakecore status

Show instructions for linking to the core libraries from your app/project

cakecore paths

CakeCore is open source software released under the MIT License. CakeCore is developed and maintained by PRONIQUE Software, a PHP Software Development Company.

Visit the CakeCore Project on github

Install and reuse CakePHP across multiple projects

Update: I have created a command line tool that provides the functionality explained in detail below. Check-out CakeCore and learn more.

How to maintain one copy of each major version of the CakePHP Core library. Making upgrades to new versions of the framework effortless even across many applications.

I use CakePHP for the majority of web-based applications I create. Before developing this convention I would end up with many redundant copies of the Core library floating around taking up disk space, and making upgrade tedious. (continue reading…)


  • cakephp multiple apps

CakePHP: Reorder lft rght columns in Tree models

CakePHP LogoIf you are using the Tree Behavior sometimes the lft and rght columns get out of sync, especially if you are adding and deleting records during development.  Add the following method to your app/app_controller.php or controller of your choice.

    * This is a maint function to recover/reorder the 
    * lft/rght columns of a tree model.
    public function recover_tree( ) {
        $modelClass = $this->modelClass;
        if ( property_exists( $this->$modelClass->Behaviors, 'Tree' ) ) { 
            if ( !$this->$modelClass->recover() ) {
                echo 'Error recovering acl tree';
            } else {
                echo $modelClass . ' reordered.';
        } else {
            echo $modelClass . ' is not a tree model';

CakePHP’s Acls implementation also uses this same Tree table structure. Since Acos and Aros often don’t have their own controllers the following method will allow you to reorder the lft rght columns in one shot. Again, add this to your AppController or controller of choice.

    * This is a maint function to recover/reorder the
    *  lft/rght columns of the aco and aro models.
    public function recover_acl_tree( ) {
        App::Import('Model', 'Aco' );
        App::Import('Model', 'Aro' );
        $Aco = new Aco;
        $Aro = new Aro;
        if ( !$Aco->recover() || !$Aro->recover() ) {
            echo 'Error recovering acl tree';
        } else {
            echo 'Aros and Acos reordered.'; 

These methods/actions are meant to be called manually as you feel needed. If you would rather call them from other controller actions I would suggest prepending ‘_’ to the method names making them private/protected methods rather than url accessible actions.

cakephp tree reorder

Starting a CakePHP 2.0 Project with cakeinit

The latest version of cakeinit (0.8.5) now includes support to create CakePHP 2.0 projects. To create a new project you only need two commands. This is an alternative to downloading the zip or tar.gz file and extracting.

# download cakeinit
curl -o cakeinit.php
# Create an app called mycakeapp based on the cakephp-2.0 bundle
php ./cakeinit.php cakephp-2.0 mycakeapp

The cakephp-1.3 bundle has also been updated to pull the recently released CakePHP 1.3.11 version of the framework. If you get some ugly permission errors don’t forget to prepend sudo to the above commands.

Read more about cakeinit at


  • cakephp 2 0 captcha

cakeinit – CakePHP Project Starter

cakeinit is a command line tool to generate new cakephp projects fast, cakeinit bundles CakePHP with various plugins to create bundles, it’s a fast way to get Cake and your favorite plugins all in one command.

Do you find yourself spending a lot of time starting new CakePHP projects? Downloading CakePHP, extract it, downloadings the plugins, components, helpers you use in every project. Well, cakeinit will save you some time.

It’s super easy!

# download it
curl -o cakeinit.php 
# run it
php ./cakeinit.php essentials mycakeapp

You can see a list of bundles by typing…

php ./cakeinit.php list-bundles

cakeinit is designed to create your project as a directory wherever cakeinit.php is located. So, if you executed the commands above in /home/foouser/projects/ your new app would be located in /home/foouser/projects/mycakeapp. Once ran, cakeinit will give you some next steps for your project.

Visit the Cakeinit Project Page

Copyright © 1996-2012 PRONIQUE Software. All rights reserved.