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.

43 Responses to “Netbeans revisited: Code Completion for Code-igniter II”

  1. My Beloved PHP » Blog Archive » Netbeans: Code Completion for the Kohana Framework Says:

    […] 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 […]

  2. Mike Says:

    That’s awesome! Thanks!

  3. Steve Says:

    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?

  4. gg Says:

    thanks … a very useful tip

  5. programmer Says:

    @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.

  6. Jeff Rubinoff Says:

    Is it OK if I link to this post and the Kohana post from the NetBeans PHP doc learning trail?

  7. programmer Says:

    Sure, please link Jeff

  8. sean Says:

    Very cool. Thanks. In your project folder structure, is your application folder the same one from the codeigniter install?

  9. Fred Says:

    Is the code missing the tag ‘<?php’?

  10. programmer Says:

    @FRED,
    Yes, for some reason it’s been eaten by wordpress

  11. programmer Says:

    @sean
    Yes I’ve placed the system folder out of the webroot for security reasons and to use it multisite.

  12. Mei Says:

    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 */

  13. Andrey Says:

    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

  14. Andrew Johns Says:

    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? 🙂

  15. Andrew Johns Says:

    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.

  16. programmer Says:

    @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.

  17. Mike Says:

    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?

  18. Rakib Says:

    @Mike,
    You have to restart netbeans EACH TIME(I guess) you add ‘@properties ….’ code snippet in any controller/model.

  19. Rakib Says:

    Awesome really excellent. You are great 🙂

  20. Rakib Says:

    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

  21. Rakib Says:

    @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.

  22. Heartshare » Blog Archive » CodeIgniter auto complete with Netbeans Says:

    […] http://www.mybelovedphp.com/2009/01/27/netbeans-revisited-code-completion-for-code-igniter-ii/ […]

  23. Richard Says:

    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?)

  24. Dookli Says:

    Thanks,

    description of iconv helped me and saved my life.

  25. brian dichiara » Blog Archive » My Experience with NetBeans Says:

    […] I noticed there was a PHP Symfony plugin for NetBeans. Maybe there’s a CI Plugin. I Google and find this blog post. […]

  26. [NetBeans] CodeIgniter?????????????? | 1000g Says:

    […] 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. […]

  27. geomorillo Says:

    great tip works perfectly

  28. Codeigniter development setting up « Yidea's Blog Says:

    […] 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′); […]

  29. Codeigniter & Netbeans PHP development setting up « Yi Cao on HCI Says:

    […] 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 […]

  30. Jeff Says:

    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!

  31. gyan84 Says:

    it works well, but only in controllers. how do I make it work in models

  32. gyan84 Says:

    it works in both controllers and models see this link.
    http://codeigniter.com/forums/viewthread/180079/

  33. Materiais, Script Online, links e infos sobre desenvolvimento web. | Criar Site Says:

    […] Code Ignitter com Netbeans auto completar […]

  34. mawey Says:

    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.

  35. Carl Friis-Hansen Says:

    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.

  36. ricardo martins Says:

    its nice to do the same with a class called CI_Model.

  37. PHP Scripts Says:

    PHP Scripts…

    […]My Beloved PHP » Blog Archive » Netbeans revisited: Code Completion for Code-igniter II[…]…

  38. Kimse Says:

    Netbeans plugin:
    http://kenai.com/projects/nbphpci/pages/Home

  39. Julian Says:

    Hi: Is there a video tutorial from this?

  40. photography section Says:

    photography section…

    […]My Beloved PHP » Blog Archive » Netbeans revisited: Code Completion for Code-igniter II[…]…

  41. Indigovara Says:

    Indigovara…

    […]My Beloved PHP » Blog Archive » Netbeans revisited: Code Completion for Code-igniter II[…]…

  42. scripts, themes Says:

    scripts, themes…

    […]My Beloved PHP » Blog Archive » Netbeans revisited: Code Completion for Code-igniter II[…]…

  43. Rosen Says:

    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…

Categories
Archives
Links