Configuring PhpStorm for use with CakePHP

This article assumes the reader is using PhpStorm 6.0.3 and CakePHP 2.3.8.

My friend Joey has gotten me interested in PhpStorm and CakePHP. His company is in love with both, so I figure there must be some value there.

The latest production release of PhpStorm, out of the box, doesn’t do a stellar job of working with CakePHP. Some files aren’t syntax highlighted, it complains about non-existent problems, and auto-complete is imperfect. These issues are easy to fix with a tiny bit of work:

Syntax highlighting. To get syntax highlighting working properly, you need to add *.ctp to the PHP file extensions list. Open PhpStorm and go to File->Settings. Click File Types, then click PHP files (PHP) in the box of Recognized File Types. Click the green + to add an entry to the Registered Patterns. Type *.ctp then click OK. Click OK to close the settings dialog and to apply your changes.

Fix a few warnings. If you are in a controller, you may notice that PhpStorm complains that: Multiple definitions exist for class AppController. To fix this (and related warnings and some auto-complete issues), go to File->Settings. Click Directories. Select lib->Cake->Console and click Excluded. Select lib->Cake->Test and click Excluded. Click OK to close the settings dialog and to apply your changes. This fix has to be done to each project.

Improve auto-complete. Added a few comments to your various files will improve auto-complete.

Controllers and Models. Add a property to the top of each controller or model that references any models you want to use in that file. For example, if your model was named Post, you would add:

<?php

/**
 * @property Post $Post
 */

?>

Views. Add the following to the top of each .ctp file:

<?php

/**
 * @var $this view
 */

?>

Auto-upload files when they are saved. I like to develop on real servers, so I set my IDE to upload my files after each save. Go to File->Settings, then find Deployment->Options. Choose On explicit save action (Ctrl+S) for Upload changed files automatically to the default server, then click OK. This is another per-project setting.

One comment

  1. Thank you sir, found this helpful.

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>