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->
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.
Create autocomplete.php and save it on your application/config/ folder
autocomplete.php structure is like this:
this is the full source code of our autocomplete.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | // 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
Code completion for our own libraries (for example I loaded our excel library) when invoked in controller
Code completion for your own model when invoked 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 can also show active record’s function description. So you know what’s the parameter (and return value) to be expected from a function
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
$query=$this->db->get('cds'); |
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
1 2 3 4 | /** * @var CI_DB_result */ $query=$this->db->get('cds'); |
Now, try typing $query-> then press Ctrl+Space, you’ll get code completion/suggestion for your database query result
Awesome stuff! I’ve been battling with this in vain for months – finally a solution that will make my life so much easier!
Excellent article!
I found one problem with code completion and using MY_Controller (in PhpEd build 7047 at least) and my own functions where not code completed. I solved this by adding the following line to autocomplete.php:
require ‘core/MY_Controller.php’;
and commenting out the following line in autocomplete.php:
class MY_Controller extends CI_Controller {};
Then all worked as a charm!
Hey your contact form is not working. I am trying to find out if you would tweak your adsense checker script to be like Google adsense sandbox and if so, for how much? Sorry for double post.
CodeIgniter is my PHP Framework of choice because of it’s comfort, extensibility and qualifications. Creating website using CodeIgniter Framework on PhpED is quite a pressure because of non-working value accomplishment for CodeIgniter’s MVC.
Hi,thanks for the info,i want to ask about adding model,i have 5 model and i have define all of it,but only shown 3 models only.Are there any workaround how to accomplish it?Thanks a lot.
could you please send me your autocomplete.php (maybe upload it to free file hosting). I’ll look at it.
This is the file,thanks.
http://dl.dropbox.com/u/78967150/autocomplete.php
I already look at it. Nothing’s wrong with your autocomplete.php.
If you wish, I can look into your models codes. You can send me your model files, upload it to free file hosting and send me the download link via contact form (so it will be private).
Hi,it already works as it should be.Thanks a lot by the way.