简体   繁体   English

如何在PHPStorm中为CodeIgniter框架启用自动完成

[英]How to enable Auto Complete in PHPStorm for CodeIgniter framework

In CodeIgniter Project, I've normally use following commands to execute sql. 在CodeIgniter Project中,我通常使用以下命令来执行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) 但不幸的是我的PHP Storm(5.0)不支持多个自动完成(我不知道怎么说)

For example in netbeans If I typed 例如在netbeans中如果我键入

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

It will auto pop up the rest of the function. 它将自动弹出该功能的其余部分。 But In PHPStorm It didn't wokring. 但在PHPStorm它并没有畏缩。 Its working first level auto complete only. 它的工作一级自动完成。

download https://github.com/topdown/phpStorm-CC-Helpers/downloads 下载https://github.com/topdown/phpStorm-CC-Helpers/downloads

Mark as Plain Text 标记为纯文本

  • /system/core/Controller.php /system/core/Controller.php
  • /system/core/Model.php /system/core/Model.php
  • /system/database/DB_active_rec.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 这就是所有Mifas链接都做同样的事情

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. 我在这里找到了一个更好的解决方案 - http://validwebs.com/346/code-completion-for-codeigniter-in-phpstorm/ ,巧合的是它来自同一作者/项目所有者Jeff Behnke。

Quoting from therein which should be read in continuation of the answer by Sabir - 从其中引用,应该在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. 将这些文件标记为纯文本会阻止phpStorm将它们作为源索引。

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. 我们在CI方式的视图中添加了一个数据数组。 Each index in the array is another variable. 数组中的每个索引都是另一个变量。

The view… 风景…

In phpStorm $test will be highlighted as an undefined var. 在phpStorm中,$ test将突出显示为未定义的var。 To fix this we use phpDoc annotations. 要解决这个问题,我们使用phpDoc注释。

 <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. 以这种方式记录不仅修复了phpStorm错误/警告,还为我们提供了$ test的文档弹出窗口。 Also the @see will link to the location it was created, in this case index method in the Welcome class. @see也将链接到它创建的位置,在本例中是Welcome类中的索引方法。

The var is now defined and shows it is. 现在已定义var并显示它。

Ctrl+ Click on this method link will bring you right to the method where $test is defined. 按住Ctrl +单击此方法链接将使您正确定义$ test的方法。

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 : 如果您希望CI中的自定义应用程序库可用于自动完成,那么这两种方案可能会有所帮助:

1. For custom extended libraries such as MY_Upload extending the CI_Upload class 1.对于自定义扩展库,例如MY_Upload,扩展CI_Upload类

Replace @property CI_Upload $upload with @property MY_Upload $upload in CI_phpstorm.php 在CI_phpstorm.php中用@property @property MY_Upload $upload替换@property CI_Upload $upload @property MY_Upload $upload

This shall make all the class variable and function names of MY_Upload available for auto-completion in addition to that of CI_Upload. 除了CI_Upload之外,这将使MY_Upload的所有类变量和函数名可用于自动完成。

2. For completely custom libraries written from scratch within the CI application - 2.对于在CI应用程序中从头开始编写的完全自定义库 -

For eg 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 例如,要从驻留在application / libraries文件夹中的Custom_Library.php启用自动完成,您需要在CI_phpstorm.php中添加到php文档@property @property Custom_Library $custom_library

I have Found it. 我找到了。

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

Please follow the read me instructions 请按照阅读说明进行操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM