Tag Archives: nusphere

NuSphere PhpED code completion for CodeIgniter Framework

NuSphere PhpED is PHP IDE of my choice since when I’m in college while CodeIgniter is my PHP Framework of choice because of it’s simplicity, extensibility and documentation. Creating website using CodeIgniter Framework on PhpED is quite a hassle because of non-working code completion for CodeIgniter’s MVC. PhpED won’t show you a list of code suggestion after you type (for example): $this->load->

phped 7 logo

this tips is tested on PhpED version 7.0 build 7044 and CodeIgniter 2.1.2

Well, that’s only until today. I solve the code completion after lurking on CodeIgniter’s getsparks.org and found Autocomplete package. The package claim to work on Netbeans and ZendStudio so I give it a try on PhpED and it does work.

This is how you do it:

Create autocomplete.php and save it on your application/config/ folder

codeigniter autocomplete in phped

This is how your application/config/ now look like

autocomplete.php structure is like this:

  1. declaration of CodeIgniter’s base class as PHPDoc virtual @property (those base class is on ‘system’ folder)
  2. declaration of your ‘models’ also as PHPDoc virtual @property. As example, I have ‘cds‘ model on my test
  3. then your own ‘libraries’ class as PHPDoc virtual @property. As example, I use our ‘pdf’ (based on pdf-php/ezpdf), ‘excel’ (based on PHPExcel) and ‘word’ (based on PHPWord) libraries
  4. and the rest .. (just follow the code.. I’ll keep it simple)

 

this is the full source code of our autocomplete.php

Now you are ready to use PhpED code completion for CodeIgniter MVC framework.

Code completion on your controller

phped code suggestion on controller

Try typing ‘$this->l’ then press Ctrl+Space 👿

Code completion for our own libraries (for example I loaded our excel library) when invoked in controller

phped code completion for excel library

example: type ‘$this->excel->’ then press Ctrl+Space 👿

Code completion for your own model when invoked inside controller

phped code completion for model inside controller

in autocomplete.php codes above, I include ‘cds’ as virtual property so I can call it’s code completion here on controller

Active record code completion in your model

phped code completion for CodeIgniter active record

It can show active record function suggestions

PhpED can also show active record’s function description. So you know what’s the parameter (and return value) to be expected from a function

phped codeigniter active record function definition

PhpED showing function definition for an active record function

 

A special case for query result

Since CodeIgniter database class’ query function returned a mixed type, PhpED can’t code-complete a variable that returned from your active record function (db->get, db->query, db->get_where, db->simple_query). For example, when you have code like this

then you try to type $query-> then press Ctrl+Space you will get a PhpED error message stating that PhpED can’t detect the $query variable type.

To overcome this, you have to use PHPDoc @var CI_DB_Result directive before $query variable, so your code would be like this

Now, try typing $query-> then press Ctrl+Space, you’ll get code completion/suggestion for your database query result

phped query result code suggestion

PhpED showing code suggestions for a query result