Using PDT with Zend Framework Projects
I original wrote this as a comment on Victor Nicollet’s blog, but I thought I should document it here too so that I can refer other people to the information.
These are some tips and tricks when using PDT with Zend Framework that make my life easier:
Zend_Db_Table_Row_Abstract uses __get() and __set() magic in order to map to the underlying database table row in question. This means that you can use property autocompletion on an instance of it. You can however tell your your table class which class to use for the row objects:
class Application_Model_Users extends Zend_Db_Table_Abstract
protected $_name = 'users'; // database table name
protected $_rowClass = 'Application_Model_User'; // row class to use
With your row class, you can take advantage of the @property docblock element to document the fields in the class:
* @property string $user_id
* @property string $username
* @property string $password
class Application_Model_User extends Zend_Db_Table_Row_Abstact
Autocomplete on instances of Application_Model_User will now work.
Zend_View scripts are more complicated as they use $this to access magic properties. You can do however use the @var trick at the top of the .phtml file:
$user = $this->user; /* @var $user Application_Model_User */
$page = $this->page; /* @var $user Application_Model_Page */
You can now autocomplete on $user and $page. This also has the side-effect of documenting which view properties are used in this view script.
View helpers are also magic methods on Zend_View’s $this within a script file. This means that you can’t cmd+click( or press F3) on the view helper’s method name to jump directly to the code for that method. You can however take advantage of PDT’s Navigation->Open Method feature. Simply select the method name and then press shift+cmd+m. The “Open Method” dialog appears and usually the view helper is selected as the first item. Just press return to go directly to the code for that view helper.
For opening up an arbitrary file that’s in my project, I find that PDT’s Navigation->Open Resource (shift+cmd+r) is handy. For TextMate users, this is similar to the cmd+t feature.
Using Navigation->Open Type (shift+cmd+t), you can also jump to classes easily. e.g. I regularly hit shift+cmd+t followed by “*Model_” and I get a list of all my models and can jump to the one I want using the down arrow key and then return.
Just press cmd+option+w. You have to be careful here as it’s very similar keyboard shortcut to close and close all! However if you have an entity file open and you name your files like I do, then the mapper is next to it in the project list, so it’s only a couple of keystrokes to open it up.
These tips obviously work with all frameworks and any PHP coding :) Netbeans also has similar features, so I would guess all IDEs do. If you are wedded to vim or such like, then ctags is helpful for jumping around your code.
If you have a favourite tip that I haven’t mentioned, let me know in the comments!