Netbeans and PHP Frameworks

Codeigniter, CakePHP & Other MVC Frameworks

Net­beans’ end-all fea­ture and sub­ject of this write-up is code com­ple­tion. It tru­ely shines when you hit Ctrl + Space. It neatly marks up, indents and auto-completes any com­bi­na­tion 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: Com­ple­tion doesn’t work for built-in func­tions of most MVC Frame­works, for instance CakePHP & Codeigniter, and between any mod­els and con­trollers you cre­ated. The con­nec­tion of all these classes within the instance of the frame­work just isn’t appar­ent to the editor.

Auto-Completion in MVC Frameworks

The rem­edy here is to add @property PHP­Doc meta data for all func­tions. Nor­mally, this would mean chang­ing all core Classes as well as your own. For­tu­nately Rak­ibul Hasan has shown us the light: By adding a pro­to­type of your Model() and Controller() func­tions in the nbproject folder you can give Net­beans the addi­tional meta data with­out touch­ing your exist­ing application.

Although it’s adver­tised for Codeigniter, it works just as well for other frame­works where all your code sits in classes extend­ing a con­troller or a model par­ent — such as CakePHP.