Loading models for autocompletion using PHPDoc @property

Hello all

I have just started using PHPStorm. I am using Codeigniter framework for PHP.
I was wondering if there is a way to load methods in a Model for autocompletion using PHPDoc @property.
What I mean is ....


class abc_controller extends Controller {

  /**
   * @property Model1
   */
  function func() {
     $this->load->model("Model1"); // I am loading the model here

     $result = $this->Model1->getIds();
     // When I type Model1 in the statement above, it should popup
     // an autocompletion box populated with all the methods of Model1
  }
}


Regards

5 comments
Comment actions Permalink

/**
* @property $Model1 Model1
   */class abc_controller extends Controller {

  
  function func() {
     $this->load->model("Model1"); // I am loading the model here

     $result = $this->Model1->getIds();
     // When I type Model1 in the statement above, it should popup
     // an autocompletion box populated with all the methods of Model1
  }
}

@property can be added only to the class phpdoc, not to the method phpdoc.

0
Comment actions Permalink

This didn't help. It shows "No Suggestions".

I added the @property to the class phpdoc. Here is how...

/**
* @property $Memos memos
*
* app/system/application/controllers/memo_controller.php
*/
class Memo_controller extends Controller {
     function index() {
          $this->load->model("Memos", "", TRUE);
          $this->Memos->getIds(); // The autocomplete didn't load it showed "No Suggestions"
     }
}



/**
* app/system/application/models/memos.php
*/
class Memos extends Model {
     function getIds() {
     }
}

Do I have to add the CodeIgniter library to the include path or external libraries or something like that.

What am I doing wrong over here?

Regards

0
Comment actions Permalink

1. Of course CodeIgniter source should be included somehow (via external libraries or directly to the project, what is more convenient for you).
2.  You use wrong format, the right one is:
@property type $var

1
Comment actions Permalink

You use wrong format, the right one is:
@property type $var

That worked. :) Thanks a lot.

0
Comment actions Permalink

You can construct this as follows, so all methods in the controller have model access type hinting without IDE error.  Hope this help someone:

/**
* Class Home
* @property home_model $home
*/
class Home extends CI_Controller
{
public function __construct()
{
parent::__construct();
// exists at application/models/Home_model.php
$this->load->model('home_model');
}

public function index()
{
// model method available in controller without IDE type-hint error
$this->home->get_payload();
}
}
0

Please sign in to leave a comment.