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

// NuSphere PhpED code completion support for Codeigniter 2.1

* Code Igniter Base class first
* @property CI_DB_active_record $db
* @property CI_DB_forge $dbforge
* @property CI_Benchmark $benchmark
* @property CI_Calendar $calendar
* @property CI_Cart $cart
* @property CI_Config $config
* @property CI_Controller $controller
* @property CI_Email $email
* @property CI_Encrypt $encrypt
* @property CI_Exceptions $exceptions
* @property CI_Form_validation $form_validation
* @property CI_Ftp $ftp
* @property CI_Hooks $hooks
* @property CI_Image_lib $image_lib
* @property CI_Input $input
* @property CI_Javascript $javascript
* @property CI_Lang $lang
* @property CI_Loader $load
* @property CI_Log $log
* @property CI_Model $model
* @property CI_Migration $migration
* @property CI_Output $output
* @property CI_Pagination $pagination
* @property CI_Parser $parser
* @property CI_Profiler $profiler
* @property CI_Router $router
* @property CI_Session $session
* @property CI_Sha1 $sha1
* @property CI_Table $table
* @property CI_Trackback $trackback
* @property CI_Typography $typography
* @property CI_Unit_test $unit_test
* @property CI_Upload $upload
* @property CI_URI $uri
* @property CI_Utf8 $utf8
* @property CI_User_agent $user_agent
* @property CI_Validation $validation
* @property CI_Xmlrpc $xmlrpc
* @property CI_Xmlrpcs $xmlrpcs
* @property CI_Zip $zip
* ==================== Put your 'models' here ======================
* @property cds $cds
* ==================== Then your own library =======================
* @property PHPExcel $excel
* @property PHPWord $word
* @property Cezpdf $pdf

class CI_Controller {};

class MY_Controller extends CI_Controller {};

* @property CI_DB_active_record $db
* @property CI_DB_forge $dbforge
* @property CI_Config $config
* @property CI_Loader $load
* @property CI_Session $session
class CI_Model {};

/* End of file autocomplete.php */
/* Location: ./application/config/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

* @var CI_DB_result

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