Using PDT with Zend Framework Projects

1st April 2010

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:

Autocompletion for dynamic properties

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 */
etc...

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.

Opening an arbitrary method

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.

Opening an arbitrary file

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.

Opening an arbitrary class

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.

Finding the current open file in the project tree

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.

Conclusion

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!

Site Stats

9th March 2008

One thing I get asked a lot about at work is site stats. Usually, the client wants to know how many visitors they get on any other day along with other data such as where the visitors came from and which search terms they may have used.

So far, I've used Google Analytics and PHPMyVisites JS based logging along with Analog on the logs themselves. I've also experimented with Mint on one site.

Generally, I've found that Analytics requires lots of drilling down to find anything, PHPMyVisites can be a little simplistic (though it is getting more features with each release) and Mint doesn't provide enough history.

Are there better solutions out that that are cost-effective for relatively small clients?

YSlow!

6th August 2007

I've been playing recently with YSlow! from Yahoo! and it's quite cool. It's a plug-in for Firefox that works in combination with Firebug that gives you pointers as to why your site isn't as fast as it could be.

I noticed that one site that I'm developing at the moment was rated C, so thought I'd see what I could do easily to improve it. These are the items that I sorted out.

Configure ETags

[notes] ETags are related to caching and don't seem especially useful from the notes, so I turned them off in my .htaccess:

FileETag none

GZip Components

[notes] For Apache 2.x, mod_deflate can be used to compress the text data that is sent to the browser. I enabled it in my .htaccess using:

<ifmodule deflate_module>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
</ifmodule>

Note that the Apache docs have better configuration settings if you need to support older browsers and other edge cases.

Add an Expires Header

[notes] The Expires header tells the browser when to look for a new version of a given file. mod_expires is the Apache module required and the .htaccess settings I've used are:

<ifmodule expires_module>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
</ifmodule>

Note Don't use the expires statements when developing!

Conclusion

There you have it. Some simple Apache configuration settings to help improve the performance of your website.

As usual, comments, criticisms and suggested improvements very welcome!