PhpStorm配置CodeIgniter(CI)框架的代碼智能提示自動補全

PhpStorm配置CodeIgniter(CI)框架的代碼智能提示自動補全

痛點

  • PhpStorm 裏面沒有CI框架的自動提示,model 找方法很抓狂?($this->load 以後再無下文)
  • model 的方法沒有自動提示,每次都要對照着model結構圖來寫。($this->xxx_model-> 以後再無下文)
  • 要達到的效果: PhpStorm支持CI的各類書寫格式,提升開發效率。

解決思路

利用註釋的 @property 來映射對應的類框架

@property 類名 實列名

舉個栗子

實現 model自定義類 this->db 鏈式提示提示

Modelthis->db 鏈式提示,咱們在 自定義model類 添加相應的@property 註釋指定 CI_DB_query_builder 類便可ui

/**
 * @property CI_DB_query_builder $db
 */
class Orderqueue_model extends MY_Model
{

}
實現 library自定義類 提示

自定義代碼會放在libraries裏面,而且會放在一個單獨的子文件夾裏。那麼這種自定義類代碼如何作代碼提示?跟model是同樣的,@property 註釋指定 CI_Queue 類便可this

/**
 * Class Queue
 * @property CI_Queue $queue
 */
class Queue extends AdminController
{

    protected $max_num = 5;


    public function __construct()
    {
        parent::__construct();
        $this->load->library('Queue', '', 'queue');
        $this->queue->get_list();// 會自動提示
    }
}

總結

網上流傳的更多方法的是,先從Git下載別人寫好的類文件,而後在你項目的External Libraries上右鍵->Configure PHP Include Path,接下來 Make as Plain Text 。本人不建議採納這樣作,其實沒這麼費勁,很簡單的一步到位,添加@property註解指定文件就能夠啦。code

相關文章
相關標籤/搜索