1

I am using CodeIgniter and have my own classes that I bounce around.

One in particular is a class that gets instantiated from my models, well actually a class that extends this does. It starts off as below,

/**
 * @var CI_Controller
 */
protected static $ci;
/**
 * @var CI_DB_active_record
 */
protected static $db;
/**
 * @var Module_Model
 */
protected static $model;

protected $dateModified = null;
protected $dateDeleted = null;
protected $dateCreated = null;

/**
 * @param stdClass $data
 */
public function __construct(stdClass $data) {

    self::$ci =& get_instance();
    self::$db = self::$ci->db;
    self::$model = self::$ci->{self::$model};

    $this->{self::$model->primaryKey} = $data->{self::$model->primaryKey};
    $this->dateModified = (self::$model->dateModified === false ? null : $data->{self::$model->dateModified});
    $this->dateDeleted = (self::$model->softDelete === false ? null : $data->{self::$model->softDelete});
    $this->dateCreated = (self::$model->dateCreated === false ? null : $data->{self::$model->dateCreated});
}

Which works fine, in the class that extends this I simply set the constructor to be:

public function __construct(stdClass $data) {

    parent::$model = 'properties';

    parent::__construct($data);
}

Which is where the line self::$model = self::$ci->{self::$model}; comes in.

It tells the class what model created is so it can access the model.

This all works great, but the issue I am having is with autocomplete.

Until the above listed line autocomplete works when calling self::$model->... it works based off the Module_Model class (which is a class all my models extend off) due to this docblock:

/**
 * @var Module_Model
 */

Now obviously no IDE is going to be smart enough to understand how Code Igniter works, and so I don't expect it to be able to autocomplete based off the model I have specified.

But, I would like it to be able to still autocomplete based off the Module_Model class.

Is there anyway (preferably through docblocks) to convince an IDE that self::$model still contains a reference to Module_Model?

If it matters I am using PHPStorm as my IDE which understands PHPdoc.

Charles
  • 50,943
  • 13
  • 104
  • 142
Hailwood
  • 89,623
  • 107
  • 270
  • 423

1 Answers1

0

You set the PHP include path in PHPStorm, follow these instructions.

Then, you may be able to adapt this answer to help you (it is for NetBeans).

Community
  • 1
  • 1
Rooneyl
  • 7,802
  • 6
  • 52
  • 81