Archive for January, 2009

Netbeans: Code Completion for the Kohana Framework

Tuesday, January 27th, 2009

In some earlier posts I’ve described ways to get Netbeans code completion working for CodeIgniter. In this post I will show you how to do the same for Kohana.

Kohana is originally a PHP-5 only fork of CodeIgniter, but it has developed into much more. Now all code has been rewritten, so only the framework in concept is based on CodeIgniter. It has nice ORM, AUTH and Cache modules.

It’s easy to convert and actually I prefer Kohana, it’s more intuitive and extensible. The only drawback: Kohana needs PHP 5.2+, where CI can be used with PHP 4.

Kohana uses the PHP class autoload feature, no need to include class files manually, PHP will lookup the file on the included path automatically at the moment the class is mentioned.
So when you write.
$this->db = New Database
The Database class declaration file will be loaded by PHP automatically. This way of lading classes is also understandable for the auto completion parser of Netbeans.

This is in contrast to CodeIgniter, because there classes are loaded like:

To achieve code completion for CodeIgniter in Netbeans we have to manually insert comments to help the auto completion parser map properties to classes:
* @property CI_DB_active_record $db

That’s not the case in Kohana, but there is another problem. Kohana uses Class suffixes. The classes are declared like Database_Core, but called like Database (without the _Core).
To evade that we grap to the netbeans_ci_code_autocompletion helper file trick. But here we don’t write the property in comments, we simple do this:
Class Database extends Database_Core{}

You can see the discussion on which this post is based in the Kohana forum. There is even a script that will generate the file automatically, so it will do extensions aswell. Works for Zend, Netbeans and Eclipse.

You can find the script here:
There is a nasty flaw though on the website, they mixed up names. The script should be activated by:
And it will create a zend_autocomplete.php file in the cache directory. You can move that to the nbproject folder if you want.

Netbeans revisited: Code Completion for Code-igniter II

Tuesday, January 27th, 2009

In an earlier post I described a way to achieve PHP code completion in Netbeans for the CodeIgniter framework. That way consisted of inserting property comments – which functioned as a helper for Netbeans to interprete the use – in every user application controller. This post will describe an even easier way, but first some comments about the earlier post.

I showed some ways to automate the inserting of the comments, although writing phpDocumentor comments in Netbeans is supported natively. Just type /** and completion will be available like explained here.

It’s a good custom to write comments in phpDoc style, it will help users to understand your coding, and it will offer an extremely easy way to publish documentation about your programs. Read here more about phpDOC.

On more remark, I wrote to include the CodeIgniter path in the Netbeans Global Include Path, it’s definitely better to do it on a project basis, so include it in the PHP Include Path in the Project Properties. Otherwise you will have CodeIgniter completion on projects that don’t use CI. 🙂

Now were getting to the core of this post. Probably the easiest way to achieve code completion is to put a file in the source path of Netbeans, but out of the CodeIgniter application or systems paths, let’s say a file called `netbeans_ci_code_completion.php`, but you can give it any name you want.

Make a text file with this content:
< ? /** * @property CI_Loader $load * @property CI_Form_validation $form_validation * @property CI_Input $input * @property CI_Email $email * @property CI_DB_active_record $db * @property CI_DB_forge $dbforge * @property CI_Table $table * @property CI_Session $session * @property CI_FTP $ftp * .... */ Class Controller { } ?>

It doens’t matter how you call it, as long it has a php extension and is seen by Netbeans but not CodeIgniter. You can save it in a folder called temp, or even in the nbproject (netbeans project folder) folder. I worked for me, and I’ve haven’t noticed any drawbacks yet.

For most of my projects I have this project folder structure:


Putting it in the nbproject folder has the advantage that the file will not by copied to the server automatically, because that folder is already marked to be excluded in the synchronization settings.

Netbeans revisited: Code Completion for Code-igniter

Friday, January 23rd, 2009

Some software you like, you start working with it, and you feel like it’s made for you. Everyday you discover a little bit more of all the hidden powers. That’s the good thing about open source, there is so much power that has yet to be discovered. Most commercial software claim a lot of features in their marketing brochures and disappoint enormously in the end when you start working.

Netbeans 6.5 is good software, out of the box it offers code completion and validation for php, html, css, javascript including jquery, mootools etc.

Code Igniter is a rapid development framework for  PHP, it’s a flexible MVC-like system. Netbeans let you easily implements CodeIgniter powers, by offering code completion for CodeIgniter’s native Active record classes, libraries and helpers functions.

You need to set it up though, and here we will explain how:

The first step is only neccesary if you have moved the system folder out of the Netbeans project source folder that contains the application folder, in case of a multi site set up or something.

Add the CodeIgniter System folder to the Netbeans Global Include Path:

Tools>Options>PHP>Add folder to  Global Include Path

This will give code completion for the helper functions and some more, but not for the Active record or database functions in a controller.


To achieve more power, add this to your controller:
* @property CI_Loader $load
* @property CI_Form_validation $form_validation
* @property CI_Input $input
* @property CI_Email $email
* @property CI_DB_active_record $db
* @property CI_DB_forge $dbforge

class Stylist extends Controller

Now you can type
And you will get all available functions offered. Wow!

To make it really easy, add this to Tools->Options->Editor->Code Templates

    1. New -> abbreviation: db
    2. Expanded text: `$this->db->`
    1. New -> abbreviation: `codei`
    2. Expanded text: `

      * @property CI_Loader $load
      * @property CI_Form_validation $form_validation
      * @property CI_Input $input
      * @property CI_Email $email
      * @property CI_DB_active_record $db
      * @property CI_DB_forge $dbforge

Now you can easily insert the Codeigniter code just above your controller, by typing `codei` and TAB
or db TAB for $this->db->

That rocks, doesn`t it.

See also here and here

Your are browsing
the Archives of My Beloved PHP for January 2009.