Using TextExpander for Code Snippets

TextExpander from Smile on My Mac is a text replacement tool, where you type in a short code and it replaces it with a pre-defined snippet. I’ve found I don’t use snippets a lot in Web Development because once I’ve done the initial setup it’s all custom coding. However I’ve found a few places where it has come in handy when developing Zend Framework applications: Zend Form, Zend Db Table and Row.

To get this setup on your computer download the free trial and create a new Group called “Zend Framework”, set the short codes to only trigger in the IDE you’re using (for me it’s Zend Studio 7.2.0)

Now create 3 new snippets in the Zend Framework Group:

Label: Zend Form
Abbreviation: zform

class _Form extends Zend_Form {
 
	public function init() {
 
		$this->setAction('/controller/action');
		$this->setMethod('post');
 
		$this->addElement(new Zend_Form_Element_Submit(array('name' => 'submit')), 'submit');		
        }
}

Label: Zend Db Table
Abbreviation: zdbtable

class _Table extends Zend_Db_Table_Abstract
{
 
    protected $_name    = 'tablename';
    protected $_primary    = 'id';
 
    protected $_referenceMap = array();
 
    public function __construct() {
    	parent::__construct();
    	$this->setRowClass('_Row');
    }
 
}

Label: Zend Db Row
Abbreviation: zdbrow

class _Row extends Zend_Db_Table_Row {
 
}

This gives you a super fast way of creating those models that you’ll be using so often, as an added bonus TextExpander comes with a snippet group just for HTML and CSS, I don’t use them with Zend Studio because it already has some good code completion features, but your mileage may vary on a different IDE.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">