A collection of Coda clips for CakePHP

Coda, the world's best IDE for Mac users, comes with a cool little feature called "clips". Its basically a snippet of code you can click on or type a "trigger" and it will output the code onto your document. I'm sharing my collection of Coda clips for CakePHP. You can download the .clips file that includes the entire collection below:

Download Coda clips for CakePHP »

Installation

Open up Coda and go to Window > Clips in the menu bar. Right-click anywhere in the left column on the clips window and choose "import group". Find the file you downloaded above and click import. You're done.

Conventions

In order to make it easy to remember I've used a certain convention for the "triggers" included in this collection.

For example, in order not to clash with any existing triggers you may already have, all of my included triggers are prefixed with a "c" for CakePHP.

Next is the letter of where in MVC the clip lives. For example, to call up the find() function within a model, that would live in the "m" prefix. So you would use the following trigger: cmfind + tab key. That will output the following: (then just easily trim back what you don't need)

$this->find('all', 
	array(
		'recursive' => -1,
		'contain' => array(
		    'Model'
		),
		'conditions' => array(
		    'Model.field' => $condition
		),
		'fields' => array(
		    'Model.field'
		),
		'order' => array(
		    'Model.field DESC'
		),
		'group' => array(
		    'Model.field'
		),
		'limit' => 10,
		'page' => 1,
		'callbacks' => true
	)
);

If you wanted to do the same as above but you're working within a controller, that would obviously be the "c" in MVC. So for the same model->find(); you would use the following trigger : ccfind + tab key. Which would output:

$this->Model->find('all', 
	array(
		'recursive' => -1,
		'contain' => array(
		    'Model'
		),
		'conditions' => array(
		    'Model.field' => $condition
		),
		'fields' => array(
		    'Model.field'
		),
		'order' => array(
		    'Model.field DESC'
		),
		'group' => array(
		    'Model.field'
		),
		'limit' => 10,
		'page' => 1,
		'callbacks' => true
	)
);

One more example for the view (and the road). I want to create a new form. Thats the "v" in MVC so I would use: cvform + tab key. Which would output the following:

<?= $form->create('Model', array('url' => ''));?>

I know it sounds kind of complicated to remember but after you've used a certain trigger once or twice, it becomes easy to remember or decipher due to the convention.

Just remember c (cakephp) + Where in MVC + trigger name

Below are examples of all the clips included in this collection. If you have a suggestion for any additional clips, drop me a line in the comments.

General Clips

Configure::read - Trigger: cconfread + tab key

Configure::read('My.value');

Configure::write - Trigger: cconfwrite + tab key

Configure::write('My.value', $value);

Model Clips

Model :: New - Trigger: cmnew + tab key

<?

class MyModel extends AppModel	{

	var $name = 'MyModel';

}

?>

Model :: Find - Trigger: cmfind + tab key

$this->find('all', 
	array(
		'recursive' => -1,
		'contain' => array(
		    'Model'
		),
		'conditions' => array(
		    'Model.field' => $condition
		),
		'fields' => array(
		    'Model.field'
		),
		'order' => array(
		    'Model.field DESC'
		),
		'group' => array(
		    'Model.field'
		),
		'limit' => 10,
		'page' => 1,
		'callbacks' => true
	)
);

Model :: Read - Trigger: cmread + tab key

$this->read(null, $id);

View Clips

View :: Debug - Trigger: cvdebug + tab key

<? debug($data); ?>

View :: For - Trigger: cvfor + tab key

<? for($i = 0; $i < $value; $i++): ?>
	
<? endfor; ?>

View :: ForEach - Trigger: cvforeach + tab key

<? foreach($items as $item): ?>
	
<? endforeach; ?>

View :: Form :: Create - Trigger: cvform + tab key

<?= $form->create('Model', array('url' => ''));?>

View :: Form :: End - Trigger: cvformend + tab key

<?= $form->end('Submit');?>

View :: Form :: Checkbox - Trigger: cvformcheckbox + tab key

<?= $form->input('Model.field', array('type' => 'checkbox', 'label' => false, 'div' => false, 'error' => false)); ?>

View :: Form :: Date - Trigger: cvformdate + tab key

<?= $form->input('Model.field', array('type' => 'date', 'label' => false, 'div' => false, 'error' => false)); ?>

View :: Form :: DateTime - Trigger: cvformdatetime + tab key

<?= $form->input('Model.field', array('type' => 'datetime', 'label' => false, 'div' => false, 'error' => false)); ?>

View :: Form :: Error - Trigger: cvformerror + tab key

<?= $form->error('Model.field'); ?>

View :: Form :: Hidden - Trigger: cvformhidden + tab key

<?= $form->input('Model.field', array('type' => 'hidden', 'label' => false, 'div' => false, 'error' => false)); ?>

View :: Form :: Password - Trigger: cvformpassword + tab key

<?= $form->input('Model.field', array('type' => 'password', 'size' => '20', 'label' => false, 'div' => false, 'error' => false)); ?>

View :: Form :: Radio - Trigger: cvformradio + tab key

<?= $form->input('Model.field', array('type' => 'radio', 'options' => $data, 'legend' => false, 'label' => false, 'div' => false, 'error' => false)); ?>

View :: Form :: Select - Trigger: cvformselect + tab key

<?= $form->input('Model.field', array('type' => 'select', 'options' => $data, 'label' => false, 'div' => false, 'error' => false)); ?>

View :: Form :: Text - Trigger: cvformtext + tab key

<?= $form->input('Model.field', array('type' => 'text', 'size' => '20', 'label' => false, 'div' => false, 'error' => false)); ?>

View :: Form :: Time - Trigger: cvformtime + tab key

<?= $form->input('Model.field', array('type' => 'time', 'label' => false, 'div' => false, 'error' => false)); ?>

View :: If - Trigger: cvif + tab key

<? if($condition): ?>

<? endif; ?>

View :: IfElse - Trigger: cvifelse + tab key

<? if($condition): ?>
	
<? else: ?>
	
<? endif; ?>

View :: Element - Trigger: cvelement + tab key

<?= $this->element('name'); ?>

View :: Session :: Check - Trigger: cvsessioncheck + tab key

$session->check('My.key');

View :: Session :: Read - Trigger: cvsessionread + tab key

$session->read('My.key');

Controller Clips

Controller :: New - Trigger: ccnew + tab key

<?

class MyController extends AppController	{

	var $name = 'MyController';

}

?>

Controller :: Debug - Trigger: ccdebug + tab key

debug($data);

Controller :: Model :: Find - Trigger: ccfind + tab key

$this->Model->find('all', 
	array(
		'recursive' => -1,
		'contain' => array(
		    'Model'
		),
		'conditions' => array(
		    'Model.field' => $condition
		),
		'fields' => array(
		    'Model.field'
		),
		'order' => array(
		    'Model.field DESC'
		),
		'group' => array(
		    'Model.field'
		),
		'limit' => 10,
		'page' => 1,
		'callbacks' => true
	)
);

Controller :: Model :: Read - Trigger: ccread + tab key

$this->Model->read(null, $id);

Controller :: Redirect - Trigger: ccredirect + tab key

$this->redirect('');

Controller :: Session :: Check - Trigger: ccsessioncheck + tab key

$this->Session->check('My.value');

Controller :: Session :: Delete - Trigger: ccsessiondelete + tab key

$this->Session->del('My.value');

Controller :: Session :: Destroy - Trigger: ccsessiondestroy + tab key

$this->Session->destroy();

Controller :: Session :: Read - Trigger: ccsessionread + tab key

$this->Session->read('My.value');

Controller :: Session :: Write - Trigger: ccsessionwrite + tab key

$this->Session->write('My.value', $value);

Controller :: Set - Trigger: ccset + tab key

$this->set('name', $value);

Comments (0)

Leave a comment

Name (Required)
Email (Required)
Url (Optional)
Comment (Required)