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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php /** * @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 { } ?> |
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”
[…] This post was mentioned on Twitter by CodeignitEE, Mahmoud O.Z.. Mahmoud O.Z. said: RT @codeignitee: RT @masnun: CodeIgniter Code Completion with the Netbeans IDE for PHP :- http://bit.ly/c7IvMW #codeigniter […]
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! :-/
Good hack! so upto release 7.0 this will solve my problems! thanks buddy for googling and summing it for me! 😉
I hope they really add CodeIgniter support on 7.0 🙂
This is exactly what I was looking for. Nice solution! Thank you very much!
working really nice thanks
Great tip … easy to follow and it worked perfectly.
You can increase the likelihood of them including this in their next release by following the link below and voting. It is currently scheduled for 6.9.1.
https://netbeans.org/bugzilla/show_bug.cgi?id=146036
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
Hi
Seems like they still haven’t added support in 7.0.
Too weird!
Hi,
I’ve got Netbeans 7.1 installed and this doesn’t seem to work. Is it because I’m using $this->email->from(…. for example?
Thanks,
Steve
You have to add the “email” properties to the parent class in a phpdoc – as a whole it’s a messy solution!
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.
Amazing Man, Thanks.