Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable Auto Complete in PHPStorm for CodeIgniter framework

In CodeIgniter Project, I've normally use following commands to execute sql.

$res = $this->db->select('*')
                 ->from('customer')
                 ->where('customer.id', $id)
                 ->get();

But unfortunatly my PHP Storm(5.0) didn't support multiple autocomplete(I don't know how to say this)

For example in netbeans If I typed

$res = $this->db->select('*')->

It will auto pop up the rest of the function. But In PHPStorm It didn't wokring. Its working first level auto complete only.

like image 290
KKK Avatar asked Oct 01 '12 09:10

KKK


2 Answers

download https://github.com/topdown/phpStorm-CC-Helpers/releases

Mark as Plain Text

  • /system/core/Controller.php
  • /system/core/Model.php
  • /system/database/DB_active_rec.php

Then Extract the downloaded archive, copy it to your project root

That's all Mifas links do the same too though

like image 163
Sabbir Avatar answered Nov 04 '22 22:11

Sabbir


Answering to a very old but still pertinent question -

I found a better solution herein - http://validwebs.com/346/code-completion-for-codeigniter-in-phpstorm/ and coincidentally it is from the same author/project owner Jeff Behnke.

Quoting from therein which should be read in continuation of the answer by Sabir -

Mark as Plain Text

/system/core/Controller.php
/system/core/Model.php
/system/database/DB_active_rec.php

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

I consider the solution in the link better because it explains the rationale behind the steps performed.

It additionally explains how we can achieve code completion in views and fix for undefined vars.

Quoting once again from the original source for easy reference and preservation herein :

Code Completion in Views and fixing undefined vars.

Example controller code.

public function index()
{
  // Example view vars
  $data['test'] = 'Testing vars in CodeIgniter!     This is from $data["test"].';

  $this->load->view('welcome_message', $data);

}

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.

<p style="font-weight: bold;">
<?php
/**
 * $data array holds the $test value
 * 
 * @see Welcome::index()
 * @var Welcome $test
 */
echo $test;
?>
</p>

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.

Herein are a few discoveries of my own while adding customisations to my project:

If you want your custom application libraries from CI to be available for auto-completion as well then there are these 2 scenarios which may be helpful :

1. For custom extended libraries such as MY_Upload extending the CI_Upload class

Replace @property CI_Upload $upload with @property MY_Upload $upload in CI_phpstorm.php

This shall make all the class variable and function names of MY_Upload available for auto-completion in addition to that of CI_Upload.

2. For completely custom libraries written from scratch within the CI application -

For e.g. to enable auto-completion from Custom_Library.php residing in the application/libraries folder, you need to add to the php doc in CI_phpstorm.php @property Custom_Library $custom_library

like image 24
Shrenik Avatar answered Nov 04 '22 22:11

Shrenik