[英]Partial code completion PHPStorm CodeIgniter 3
(PHPStorm version 8.0.3 with CodeIgniter 3, running on Mac OS X Yosemite 10.10.3) (在Mac OS X Yosemite 10.10.3上运行的具有CodeIgniter 3的PHPStorm版本8.0.3)
As the title states, I currently experience partial code completion. 如标题所示,我目前遇到部分代码完成。
At first I had nothing, I used the following link to add the partial part: 一开始我什么都没有,我使用以下链接添加了部分内容:
I can now for example see the code completion for $this->...
, thus giving me options at first I didn't had. 例如,现在我可以看到
$this->...
的代码完成,因此一开始就给了我一些我没有的选项。
I do get an 'unfound' method warning message from PHPStorm when I use $query->row_array();
当我使用
$query->row_array();
时,我确实从PHPStorm收到“未找到”方法警告消息$query->row_array();
after assigning $query = $this->db->get_where('news', array('slug' => $slug));
在分配
$query = $this->db->get_where('news', array('slug' => $slug));
. 。 So in this case my code completion doesn't work (It can't find it).
因此,在这种情况下,我的代码完成无法正常工作(无法找到它)。
The full code of this class is found beneath. 此类的完整代码在下面。
class News_model extends CI_Model
{
public function __construct()
{
$this->load->database();
}
public function get_news($slug = FALSE)
{
if($slug === FALSE)
{
$query = $this->db->get('news');
return $query->result_array();
}
$query = $this->db->get_where('news', array('slug' => $slug));
return $query->row_array();
}
}
When I run a search for the method 'row_array' it is found under 'System' > 'database' > 'db_result.php'. 当我搜索方法“ row_array”时,可以在“系统”>“数据库”>“ db_result.php”下找到它。 So it is defined, but PHPStorm can't give me code completion
这样就定义了,但是PHPStorm无法给我代码完成
How can I fix this? 我怎样才能解决这个问题?
From my understanding. 据我了解。
As long as you followed one of these options 只要您遵循以下选项之一
Option 1 = File > Settings > Directories > Add Content Root > Select the directory in phpStorm-CC-helpers that is relevant > mark Resource Root
选项1 =文件>设置>目录>添加内容根>在phpStorm-CC-helpers中选择相关目录>标记资源根
Option 2 = In the project window right click External Libraries > Configure PHP Include Paths Then add the path to the phpStorm-CC-helpers that is relevant
选项2 =在项目窗口中,右键单击“外部库”>“配置PHP包含路径”,然后将路径添加到相关的phpStorm-CC-helpers
Then according to the helper annotations /CI_DB_active_record
is what it is returned when you call get_where
. 然后根据帮助程序注释,
/CI_DB_active_record
是调用get_where
时返回的get_where
。 Ensure that the file /system/database/DB_active_rec.php
is marked as plain text so that the IDE can parse it for autocomplete. 确保将文件
/system/database/DB_active_rec.php
标记为纯文本,以便IDE可以对其进行解析以实现自动完成。
If you are using CodeIgniter 3, /system/database/DB_active_rec.php
and the /CI_DB_active_record
class was removed from the CodeIgniter source, so there would be no reference found for /CI_DB_active_record
that the helper references. 如果您使用的是CodeIgniter 3,
/system/database/DB_active_rec.php
从CodeIgniter源中删除/system/database/DB_active_rec.php
和/CI_DB_active_record
类,因此将找不到该助手所引用的/CI_DB_active_record
的引用。
I just tested this and it I can confirm that it does work, its not ideal but it will produce autocomplete for the $query var. 我刚刚测试了一下,它可以确认它确实有效,虽然不理想,但会为$ query var产生自动完成功能。
I used this in the route of my project. 我在我的项目路线中使用了它。 https://gist.github.com/gentoid/4353692
https://gist.github.com/gentoid/4353692
Then you have to do the code like this: 然后,您必须执行以下代码:
public function index($slug)
{
/** @var CI_DB_result $query */
$query = $this->db->get();
//this will now produce auto complete in PHPStorm because
//it knows that object the $query var contains.
//$query->
}
also you can do this 你也可以做到这一点
/**
* @return CI_DB_result
*/
public function getData()
{
return $this->db->get();
}
public function test()
{
$query = $this->getData();
//this will now produce auto complete in PHPStorm because
//it knows that object the $query var contains.
//$query->
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.