Netbeans revisited: Code Completion for Code-igniter II
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:
/application
/error
/images
/nbproject
/scripts
/styles
index.php
.htaccess
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.
January 27th, 2009 at 5:02 pm
[…] 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 […]
February 5th, 2009 at 5:56 am
That’s awesome! Thanks!
February 7th, 2009 at 4:30 pm
Hi,
Have you heard of a CodeIgniter project type, or file types for CI files? That would be another way to get the comments pre-stamped into CI PHP files… I haven’t found any, but perhaps you have?
February 13th, 2009 at 10:58 am
thanks … a very useful tip
February 20th, 2009 at 11:52 am
@Steve. No, that’s a thing a like about Kohana. Kohana::list_files. I would make the step to Kohana iif all servers were > php 5.2.
March 3rd, 2009 at 7:14 pm
Is it OK if I link to this post and the Kohana post from the NetBeans PHP doc learning trail?
March 12th, 2009 at 9:27 am
Sure, please link Jeff
March 20th, 2009 at 9:23 pm
Very cool. Thanks. In your project folder structure, is your application folder the same one from the codeigniter install?
April 16th, 2009 at 4:04 pm
Is the code missing the tag ‘<?php’?
April 16th, 2009 at 6:31 pm
@FRED,
Yes, for some reason it’s been eaten by wordpress
April 16th, 2009 at 6:34 pm
@sean
Yes I’ve placed the system folder out of the webroot for security reasons and to use it multisite.
May 22nd, 2009 at 2:36 pm
I’ve got this in a template file called CI Controller, and a CI Model file with similar…
if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed.’);
/**
*
*
* @property CI_Loader $load
* @property CI_Form_validation $form_validation
* @property CI_Input $input
* @property CI_Email $email
*/
class XXX extends MY_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
}
} // EOC
/* end of file ./application/controllers/XXX.php */
June 21st, 2009 at 1:00 pm
You should know that code completion will not work if nb project structure looks like:
some_dir/
application
images
…
cc works only if application folder is first-level folder in project
August 26th, 2009 at 12:23 pm
maybe I did something wrong, but I originally had my structure like this:
htdocs/CIsystem/
htdocs/Website/app
This was so that CISystem could be used across multiple hosted sites, and each website would be a netbeans project, so it had a nbproject folder in it, which is where I placed the file you suggested above.
What I noticed is that I didn’t get proper full on code completion with this structure until I put the files in CISystem folder back inside the project.
So I either had two choices, one project file for multiple websites, or move the CI system folder back inside my website project folder.
Unless I’ve done something wrong? 🙂
August 26th, 2009 at 8:51 pm
actually, I have another question you might be able to answer!
I had a number of classes and collection classes in an old project, that are mostly object structures, with getter/setter functions, which I’d created so that I could get lovely netbeans code completion on my objects while looping through things and so on. It just felt the right thing to do.
However, as i’m now trying to build a project using CI, I want to use this lot in a new library for CI, but I want to be able to access this library and get Code Completion.
e.g:
$this->someclass->some_function(param);
actually, going one step further, can a library hold multiple classes? e.g. I load “mylibrary” and then I can get access to:
$this->mylibrary->SomeClass->someFunction(param);
or perhaps more likely:
$myObject = $this->mylibrary->someClass();
so that I can then do:
$myObject->someFunction(param);
?
I think I’m going to have to pose this question in the forum but it’s down at the moment, grrr.
August 28th, 2009 at 4:25 pm
@Andrew
I do the same as you. One core CI system directory for multiple sites:
1 easy updating
2 better performance (file-caching)
Don’t forget to include the CI system directory to the PHP include path at the Project Properties.
That should work!
@Andrey probably answered your question as well.
August 31st, 2009 at 1:21 pm
I’ve tried to follow the instructions above and the code competition doesn’t seem to be working for me.
So far I’ve added my system folder to the include path and created a directory temp with a folder inside called “netbeans_ci_autocomplete.php”. Is there something I’m missing here?
September 1st, 2009 at 8:19 am
@Mike,
You have to restart netbeans EACH TIME(I guess) you add ‘@properties ….’ code snippet in any controller/model.
September 1st, 2009 at 4:16 pm
Awesome really excellent. You are great 🙂
September 1st, 2009 at 4:35 pm
Hi,
It works only with controller. How can I get it working with model. Because I have to use $this -> db …. in all model… Plz give a solution
September 1st, 2009 at 4:39 pm
@Mike,
Sorry, I have installed netbeans 6.7 and i don’t need to restart at all to get it working. But with netbeans 6.5 I had to do it. Weird though.
October 4th, 2009 at 3:13 am
[…] http://www.mybelovedphp.com/2009/01/27/netbeans-revisited-code-completion-for-code-igniter-ii/ […]
February 19th, 2010 at 6:58 am
using this structure
home
— application (your ci application)
— system (ci system)
— www (css,js and index.php)
set source folder and project folder as home
set web root as the www folder
code completion etc works – no need for hooks etc.
to debug just click debug let debug attach then remove ?xdebug string and continue as usual – (know an automatic fix?)
April 20th, 2010 at 5:58 pm
Thanks,
description of iconv helped me and saved my life.
May 18th, 2010 at 11:57 pm
[…] I noticed there was a PHP Symfony plugin for NetBeans. Maybe there’s a CI Plugin. I Google and find this blog post. […]
May 27th, 2010 at 7:11 am
[…] My Beloved PHP » Blog Archive » Netbeans revisited: Code Completion for Code-igniter II CodeIgniter, PHP, ???, ????CodeIgniter, NetBeans, ???? ← [CodeIgniter] CodeIgniter1.7.2 ? SQLite3 ?DB??? Leave a comment0 Comments. […]
July 30th, 2010 at 6:30 am
great tip works perfectly
August 18th, 2010 at 3:47 am
[…] code completion for Codeigniter how to change XAMPP server port to 80 Using strings for URI segments in CI debuging with CI in firephp setting up 1 how to setup and use CVS in netbean 6(this is a Chinese webpage) setting up CI with firephp 2 set fireignition_enabled = true under config/fireignition.php to make firephp work ,turn it to false after debugging exp:$this->firephp->log(‘content1′,’label1′); […]
September 5th, 2010 at 10:57 pm
[…] upload function setup on Netbeans code completion for Codeigniter how to change XAMPP server port to 80 Using strings for URI segments in CI debuging with CI in […]
March 8th, 2011 at 11:54 pm
If it is not working with CodeIgniter 2.0 for you, this may help:
I spent about 2 hours banging my head until I realized 2 things that need to be changed from the snippet:
1. the ‘php’ was stripped from the opening tag
2. (for CI 2.0 only… I think) change the class declaration from Controller to CI_Controller.
Hopefully that helps someone out!
March 16th, 2011 at 12:00 pm
it works well, but only in controllers. how do I make it work in models
March 16th, 2011 at 12:45 pm
it works in both controllers and models see this link.
http://codeigniter.com/forums/viewthread/180079/
June 3rd, 2011 at 2:35 pm
[…] Code Ignitter com Netbeans auto completar […]
August 8th, 2011 at 1:32 pm
Hi to everybody,
I’m new to CI, but I’ve got several sites/web solutions working in php. I use NetBeans 7.0.1 for coding over XAMPP.
I’m trying to adapt CI and I’m not sure where to place the folders it needs. CI comes with three folders: user_guide, application and system.
I know “application” should be copied inside every project using CI as the author suggested above.
Nothing to say about “user_guide”.
But, where should I put “system”? in htdocs? in every project-folder as “application”?
Thanks a lot for your reply in advance.
August 25th, 2011 at 9:10 pm
Hi Mawey,
I put the system folder outside the doc-root and have all websites using that same system folder. In the main index.php file:
$system_path = ‘/home/../../../system’;
you set the path to the system folder.
It is then very easy to update the core of CI for all users at the same time.
October 6th, 2011 at 5:10 pm
its nice to do the same with a class called CI_Model.
October 29th, 2011 at 11:58 am
PHP Scripts…
[…]My Beloved PHP » Blog Archive » Netbeans revisited: Code Completion for Code-igniter II[…]…
November 15th, 2011 at 10:42 am
Netbeans plugin:
http://kenai.com/projects/nbphpci/pages/Home
January 13th, 2012 at 8:36 pm
Hi: Is there a video tutorial from this?
January 18th, 2012 at 2:45 pm
photography section…
[…]My Beloved PHP » Blog Archive » Netbeans revisited: Code Completion for Code-igniter II[…]…
January 20th, 2012 at 10:20 pm
Indigovara…
[…]My Beloved PHP » Blog Archive » Netbeans revisited: Code Completion for Code-igniter II[…]…
May 9th, 2012 at 8:06 pm
scripts, themes…
[…]My Beloved PHP » Blog Archive » Netbeans revisited: Code Completion for Code-igniter II[…]…
May 15th, 2012 at 11:13 pm
i put the file in the C:/Program Files/NetBeans/ directory but code completion still doesn’t work… i mean when i type $this->load-> for example nothing shows even when i press ctrl + space…