AutoHotkey Guide for CakePHP

By Troy (Tr0y)
Tired of typing "class YourModelsController extends AppController..." over and over? If so this, is for you.
NOTE: This guide assumes you are using PHPeclipse as your IDE of choice. If you use another IDE or notepad you will have to adjust the AutoHotkey script accordingly.

Step 1

Download and Install AutoHotkey ( it's free ) - http://www.autohotkey.com/

Step 2

Edit the default script to look like the following.

Download code
;-----------------------------------------------------------------------------
;    CakePHP
;-----------------------------------------------------------------------------

;model
:c*?:]cmod::
InputBox, MyModel, Model Name Prompt, Enter model name ( e.g. MyModel ),,250,125
if ErrorLevel=0
{
    BlockInput On
    Send, class %MyModel% extends AppModel{enter}{{}{enter}var $name = '%MyModel%';{tab}// required for php4 installs{enter}var $displayField = 'id';{enter}
    BlockInput Off
}
return

;controller
:c*?:]ccon::
InputBox, MyModels, Models Controller Prompt, Enter controller name ( e.g. MyModels ),,250,125
if ErrorLevel=0
{
    BlockInput On
    Send, class %MyModels%Controller extends AppController{enter}{{}{enter}var $name = '%MyModels%';{tab}// required for php4 installs{enter}var $scaffold;{enter}
    BlockInput Off
}
return


Step 3

Fire up PHPeclipse and create a model php file.

Reload the script by right-clicking the taskbar icon and reload.

type ]cmod

It should prompt you for the model's name, so type your models name.

For controllers type ]ccon

 

Comments 73

CakePHP Team Comments Author Comments
 

Comment

1 textmate

if you're on a mac, just try out textmate (macromates.com) and its bundles.

there is one for cakephp to do things like this automatically.
Posted Oct 3, 2006 by Claudio Poli
 

Comment

2 SCiTE

Or for none-mac users, you can use SCiTE -- which is a VERY handy editor.

It has the same snippets functionality as Textmate and they are user-definable with an easy-to-understand syntax. Just define a set of snippets you find valuable and it's just a keyword and ctrl-b away.

If anyone is interested, I can post my snippets file (known to SCiTE users as an abbreviations file).
Posted Oct 26, 2006 by James
 

Comment

3 Do It

^ Yea, I'd be interested in some snippets.

:-)
Posted Oct 30, 2006 by Troy
 

Comment

4 Vim

For Vim users you can get the snippetsEmu script to have snippets just like Textmate :-)

http://www.vim.org/scripts/script.php?script_id=1318
Posted Nov 17, 2006 by Carlos Zuniga
 

Comment

5 PHPeclipse

you can define shortcuts like mentioned above in eclipse so you do not need autohotkey. just go to the templates in PHPeclipse user settings and create your own templates, e.g.

/**
 * @author ${user}
 * @since ${date}
 */
class ${primary_type_name} extends AppModel {
    var $$name = '${primary_type_name}';
    
    var $$hasMany = array();
    var $$belongsTo = array();
    var $$hasAndBelongsToMany = array();
    
    ${cursor}
}

when you create a new model just type 'model' and press ctrl + space and eclipse inserts the model code. ${primary_type_name} inserts the filename without extension so there is almost nothing to do left :-).
Posted Mar 14, 2007 by sunertl
 

Comment

6 GENNIT CakePHP Generator

Have a look at http://gennit.com it does code generation for CakePHP, and creates the MySQL database as well.
Posted Nov 8, 2007 by Gary