Netbeans: Code Completion for the Kohana Framework
Tuesday, January 27th, 2009In 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:
$this->load->library('validation')
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{}
etc
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:
http://www.mapledesign.co.uk/code/kohana-zend-autocomplete/
There is a nasty flaw though on the website, they mixed up names. The script should be activated by:
http://yoursite/zend_ide
And it will create a zend_autocomplete.php file in the cache directory. You can move that to the nbproject folder if you want.