Netbeans and PHP Frameworks

Codeigniter, CakePHP & Other MVC Frameworks

Netbeans’ end-all feature and subject of this write-up is code completion. It truely shines when you hit Ctrl + Space. It neatly marks up, indents and auto-completes any combination of PHP, HTML, CSS & JS you throw at it – even if they’re all in the same PHP file.

There’s just one issue I’ve run into: Completion doesn’t work for built-in functions of most MVC Frameworks, for instance CakePHP & Codeigniter, and between any models and controllers you created. The connection of all these classes within the instance of the framework just isn’t apparent to the editor.

Auto-Completion in MVC Frameworks

The remedy here is to add @property PHPDoc meta data for all functions. Normally, this would mean changing all core Classes as well as your own. Fortunately Rakibul Hasan has shown us the light: By adding a prototype of your Model() and Controller() functions in the nbproject folder you can give Netbeans the additional meta data without touching your existing application.

Although it’s advertised for Codeigniter, it works just as well for other frameworks where all your code sits in classes extending a controller or a model parent – such as CakePHP.