Code Completion for CodeIgniter in phpStorm

phpStorm Logo Open source projects can sometimes be a bit of a pain in phpStorm.
Here I am going to show how to fix code completion for CodeIgniter in phpStorm.

Common Issues

Undefined fields or methods not found.

No code completion.

This one is complained about a lot, undefined vars in views.

When we are done, all of these issues will have solutions.

I have created a document that has CI_Controller class and CI_Model.
The goal here is to not modify CodeIgniter core code, that is always a bad idea.

I wont post the code here because it is quite long.
But I will give links to the repo and Gist on GitHub.
You can decide how to download it.

The setup

  • Download the CI_phpStorm.php file with your preferred method.
  • Put it in the root of your CodeIgniter project (where the index.php is)
  • In phpStorm project nav pain, go to (expand) system/core/
  • Right click on Controller.php and Mark as Plain Text
  • Do the same for Model.php

Marking those files as plain text stops phpStorm from indexing them as sources.

Now if you go to a controller in your project like the default welcome.php, you should have code completion and the earlier issues fixed.

Doc Block Info Popups

Property Completion

Method completion.

As you can see from the above images that all code completion is now working in the controllers.
You should have most of the same completion in models with some annotations here and there.

Code Completion in Views and fixing undefined vars.

Example controller code.

We added a data array to the view the CI way.
Each index in the array is another variable.

The view…

In phpStorm $test will be highlighted as an undefined var.
To fix this we use phpDoc annotations.

Documenting this way not only fixes the phpStorm error/warning but also gives us documentation popup for $test.
Also the @see will link to the location it was created, in this case index method in the Welcome class.

The var is now defined and shows it is.

Ctrl+ Click on this method link will bring you right to the method where $test is defined.

This should get you headed in the right direction working with CodeIgniter in phpStorm.
The fundamentals are pretty much the same when working with any project in phpStorm.

Once you become use to it, its easy.
Proper phpDocs and annotations also better explain what your code is doing when others look at it.

Good luck and until next time Happy Coding

  • jonatanfroes

    does it work w/ HMVC?

    • It will, but it will most likely need to be adjusted for it depending on how the HMVC is setup.

      So its going to depend on the HMVC.
      I worked with a couple CI CMS’s about 6 months ago that were HMVC and was able to get most code completion working.
      But each was different to setup.

  • leschirmeur

    Hi Jeff!

    Great stuff, thanks very much.

    However, I am still getting warning messages for code like
    “$query->row_array()” where phpstorm does not regonize the row_array() method.

    Any ideas what I am doing wrong here?

    Thanks very much and kind regards

    • My comment system is broke at the moment. Comments are all messed up.
      Anyway, assuming your referring to CI, mark your query with an var annotation.


      will work.
      This is because $this->db uses multiple dynamic instances and we can only assign one at a time.

      In my phpStorm helper file I assigned this->db to CI_DB_active_record
      For the initial methods and properties.
      After that when you assign the var $query to that instance you need to re-annotate it to get the drivers methods, IE


      You might get lost trying to reply, like I said my comment system is a mess.
      Should have it fixed tomorrow though.

      Hope the above helps. It should.

  • Pingback: Panda()

  • Wow. It’s great.

  • So GOOD! TKS~

  • zarpio

    Thanks for your great sharing. Can you please help me out I want auto-complete in my view files. I have created a library and added /* @property Site $site My Library for Site */ auto-complete is working fine in controllers and models but how can it work in the view files?

    • You will have to add /** @property Site $site My Library for Site */
      To the views that you want it to work in.

      • zarpio

        Thank you for your reply, but I am still not able to get autocomplete working. Can you please advise, how should I access library methods. I am trying “$this->site->myfunc();” is it correct ?

  • Miguel

    Thank you very much!

  • Jordani

    How can i configure Codeigniter in PHPStorm?

  • anan234

    is it works in HMVC…?

    • No idea, I have not messed with it for years. It should work but will probably require putting the info in the different paths.