Welcome Guest, Not a member yet? Register   Sign In
[split] CI3 Code Completion for library with PhpStorm
#1

(This post was last modified: 09-07-2016, 09:53 PM by ciadmin.)

Has anyone gotten code completion to work from within a library with phpStorm?
I have an autocomplete.php file in my config dir and all autocompletes work correctly except for inside a library file.

For example:

class Some_custom_lib {
   protected $CI;

   public function __construct() {
       $this->CI =& get_instance();
       $this->CI->load->model('some_custom_model');
   }

   public function createSubrofile($post_vars) {
       $create_file = $this->CI->some_custom_model->create_file($post_vars); // <-- This will not autocomplete.
       if($create_file){
           return array( 'code' => 200, 'message' => $create_file );
       } else {
           return array( 'code' => 400, 'message' => array( 'error' => 'Error creating file.' ) );
       }
   }
Reply
#2

(This post was last modified: 09-07-2016, 10:34 PM by salain.)

Try this works fairly well
https://github.com/nicolas-goudry/CI-PHP...Completion

I use Third Method
A good decision is based on knowledge and not on numbers. - Plato

Reply
#3

(09-07-2016, 10:14 PM)salain Wrote: Try this works fairly well
https://github.com/nicolas-goudry/CI-PHP...Completion

I use Third Method

I tried that also. It to works perfectly for autocomplete everywhere EXCEPT inside a library file. Still looking for a solution...
Reply
#4

It works in library.
Have you added your libraries and models?
Libraries have to be added in the CI_Controller and CI_Model sections.
Models only in the CI_Controller section.
A good decision is based on knowledge and not on numbers. - Plato

Reply
#5

Suppose that you have a library class name Foo like:

PHP Code:
class Foo 
{

 
 private CI;

 
 public function __construct()
 
 {
 
    $this->CI =& get_instance();
 
 }



In order to PHPStrom know that that object is handling the CI instance, should add this comment to your class:

PHP Code:
class Foo 
{
 
 /**
  * @var CI_Controller
  **/
 
 private CI;

 
 public function __construct()
 
 {
 
    $this->CI =& get_instance();
 
 }

And, as salan said : 
Quote:Libraries have to be added in the CI_Controller and CI_Model sections.
Reply
#6

Hi salain,

Yes, I did add it to both sections. This enables autocomplete of the library functions from inside a controller but autocomplete from inside the library for models does not work. I finally gave up and moved all my library code into models just to get autocomplete. Sad
Reply
#7

Hi tduncklee,

I think you need this comment at the top of your libraries to fix the autocomplete of the model
@property CI_Controller $_ci
The variable has to be the same as the get_instance is assign to.
A good decision is based on knowledge and not on numbers. - Plato

Reply
#8

That's it! It's actually:
@property CI_Controller $ci (no _ )
It works! Thanks! Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB