How to work really comfortable with the Netbeans IDE. Two conditions: stay away from the mouse, rely on short keys and rely on autocompletion. Case at hand: a Zend Framework II (ZF2) project.

Netbeans supports auto completion also called code assistance (link) . It opens documentation, it helps selecting class methods and method arguments. It autocompletes class paths and namespaces.

Useful keyboard shortcuts:
– control space :: open code assistance box
– control B :: switch to file containing the class / method (alt F10 close file again)
– control shift F :: search in the entire project
– CNTR SHIFT 1 :: highlight file in file tree
– ALT SHIFT O :: Open a file

Netbeans is not always aware of classes. A notorious case in the context of ZF2 are services. In cases like these docblocks help:

/* @var $user \Application\Model\User */
$user = $this->getServiceLocator()->get('User');

Netbeans now recognises the $user variable as an User class again.

Notes
* If the user class extends another class then make sure the extending class is explicitly mentioned in the namespace declaration.
* Extending code assistance to the Zend library itself may require adding the Zend folder to the Window >> options >> PHP >> General >> Global Include Path

* Autogenerate getters and setters in a model: ALT + INSERT, just make sure the cursor is where you want the method to be created

Advertisements