Categories
PHP

CodeIgniter Code Completion with the Netbeans IDE for PHP

CodeIgniter is my favorite web application framework for PHP and Netbeans is the IDE I use for all sorts of web development. The latest version of Netbeans IDE (6.9) has support for both Symfony and Zend Framework. But it still has no official support for CodeIgniter. So, in the default installation, you will always miss the fantastic code completion feature of the IDE.

After Googling a while, I just learned a magic trick that can emulate this feature in Netbeans. The process is pretty simple. We feed Netbeans a php file that has a simple sample “Controller” class definition that has phpdoc specifying the necessary properties. We put this file in a place readable by the IDE but invisible or worthless for the CodeIgniter framework. The “nbproject” directory inside the project root could be a good place to put this file. What really happens is that Netbeans reads the phpdoc and offers the completion of the specified properties in any class that extends the Controller class. Hiding it from CodeIgniter helps not to mess up with the system.

This is what I did. I created a php file and named it “nb.php”. I filled this file with the following contents:

And put the file inside my nbproject directory. Now I am getting code completion in my Netbeans for CodeIgniter.

17 replies on “CodeIgniter Code Completion with the Netbeans IDE for PHP”

It’s a shame we still have to faff around doing this in each project, 6.9 was supposed to include this feature but they have moved it to 7.0 now.

Here’s hoping! :-/

I have Netbeans 6.8 and CodeIgniter 1.7.2.

I have tried the methods above, placing the properties in a php file in nbproject as well as directly in my controller before any functions.

When I type:

$this->l //lower case L

I see a list pop up as expected but only listing items like “language(), and library()” .
If I continue to type the list disappears as soon as I hit the letter ‘o’. I re-type the ‘$this->l’ and manually scroll through the list. There is ONLY overloads for ‘language()’ and ‘library()’ nothing else.

Why does the line:

* @property CI_Loader $load

get over looked?

Please remove the instance before the controller and see if that helps. I am not sure why this is happening. May be putting it twice is making some sort of collisions.

No sorry, you mis-understand me… I did try both but at separate times. They were never both applied at the same time so there was no collision.

Test 1:
place file in nbproject folder
restart Netbeans
Result: No ‘load’ in list

Test 2:
Remove file from nbproject
Add properties to class above functions but inside class .
restart netbeans
Result: No ‘load’ in list

I did get this to work finally but I am not sure I like how I made it work. I added all 3 files in the ci_autocomplete.zip file to my views folder under application. I did not even have to restart netbeans. I did not run the script and it is not listed in my controller or in my model.

My question is, what are the security implications here?
If they are not exposed by any controller or model is it safe to have these files in the views folder?

Here is some history that I believe explains my issue:
When I installed NetBeans and then created the project I was at some point asked if I wanted to store my projects metadata in the same folder with my project source files. I said ‘no’.

This means that my nbproject folder is now in my home directory under the NetBeans folder example:

/home/<username>/NetBeans/<projectname>/nbproject

This is (I believe) the root of my issues, or at least what has confused me in terms of location of the ci_autocomplete files.

Never mind, I was able to make a directory (/var/www/<CI-ROOT>/system/application/ci_autocomplete) and move all 3 autocomplete files into this and it all still works!

It files only have to be in a folder 2 levels below the system folder. The folder can be any name and as log as the autocomplete php files can find system at ../../system all works apparently.

This removes my concern for the views folder and allows all to work ok

Also in my above post I mentioned a folder:
/home/<username>/NetBeans/<projectname>/nbproject

That should have been:
/home/<username>/NetBeansProjects/<projectname>/nbproject

is it too difficult to create a decent netbean plugin for this or what? Someone who has been using this for a long time will probably be the best subject.

Comments are closed.