【问题标题】:IntelliJ IDEA 12 not finding CodeIgniter classes, throwing errorsIntelliJ IDEA 12 找不到 CodeIgniter 类,抛出错误
【发布时间】:2013-03-15 04:35:45
【问题描述】:

我正在使用 IntelliJ IDEA 12 开发一个使用 CodeIgniter 框架的 PHP Web 应用程序。由于 CI 实例化对象和方法的方式,IDEA 认为它们在被调用时并不存在:

如您所见,在我尝试使用的每个 CodeIgniter 类/方法下,我都会遇到那些烦人的橙色曲线。

下面是 CI_Controller 类的代码,可以深入了解它们是如何创建对象的:

class CI_Controller {

    private static $instance;

    /**
     * Constructor
     */
    public function __construct()
    {
        self::$instance =& $this;

        // Assign all the class objects that were instantiated by the
        // bootstrap file (CodeIgniter.php) to local class variables
        // so that CI can run as one big super object.
        foreach (is_loaded() as $var => $class)
        {
            $this->$var =& load_class($class);
        }

        $this->load =& load_class('Loader', 'core');

        $this->load->initialize();

        log_message('debug', "Controller Class Initialized");
    }

    public static function &get_instance()
    {
        return self::$instance;
    }
}

有什么方法可以让 IntelliJ IDEA 忽略这些错误(但不是其他错误),或者让它自己找到对象?

注意:我曾经使用 PHPStorm,这是一个在 IntelliJ IDEA 平台上构建的 PHP IDE,它在 CodeIgniter 上做了同样的事情。

【问题讨论】:

  • 使用Aptana。它非常适合Codeigniter
  • @YogeshSuthar 我会研究一下,但我更喜欢让 CI 与 IntelliJ IDEA 一起工作的解决方案。
  • 谷歌搜索显示您不是唯一有问题的人。我使用 Sublime Text,它非常适合 CI——甚至还有一些由第三方创建的代码完成插件。
  • jetbrains 上有一个关于 CI 支持的功能请求。我不认为他们会继续这样做,但这不会影响投票:youtrack.jetbrains.com/issue/WI-1174

标签: php codeigniter ide intellij-idea


【解决方案1】:

我通过关注this guide 解决了这个问题。它适用于 PHPStorm,但也适用于 IntelliJ IDEA(可能也是 WebStorm!)。其实很简单。基本回顾:

  1. 在我的项目根目录中保存了以下 PHP 代码。它基本上只是一个 PHPDoc 注释:
还可以显示内存消耗。 * @property CI_Calendar $calendar 这个类可以创建日历 * @property CI_Cart $cart 购物车类 * @property CI_Config $config 此类包含使配置文件能够被管理的函数 * @property CI_Controller $controller 这个类对象是每个库所在的超类。
CodeIgniter 将被分配到。 * @property CI_Email $email 允许使用 Mail、Sendmail 或 SMTP 发送电子邮件。 * @property CI_Encrypt $encrypt 使用 XOR Hashing 和 Mcrypt 提供双向密钥编码 * @property CI_Exceptions $exceptions 异常类 * @property CI_Form_validation $form_validation 表单验证类 * @property CI_Ftp $ftp FTP 类 * @property CI_Hooks $hooks 提供一种机制来扩展基本系统而无需黑客攻击。 * @property CI_Image_lib $image_lib 图像处理类 * @property CI_Input $input 预处理全局输入数据以确保安全 * @property CI_Lang $lang 语言类 * @property CI_Loader $load 加载视图和文件 * @property CI_Log $log 日志记录类 * @property CI_Model $model CodeIgniter 模型类 * @property CI_Output $output 负责将最终输出发送到浏览器 * @property CI_Pagination $pagination 分页类 * @property CI_Parser $parser 解析指定模板视图中包含的伪变量,
用第二个参数中的数据替换它们 * @property CI_Profiler $profiler 此类使您能够显示基准、查询和其他数据
以帮助调试和优化。 * @property CI_Router $router 解析 URI 并确定路由 * @property CI_Session $session 会话类 * @property CI_Sha1 $sha1 使用安全散列算法提供 160 位散列 * @property CI_Table $table HTML 表生成
让您可以手动或从数据库结果对象或数组创建表。 * @property CI_Trackback $trackback Trackback 发送/接收类 * @property CI_Typography $typography 排版类 * @property CI_Unit_test $unit_test 简单测试类 * @property CI_Upload $upload 文件上传类 * @property CI_URI $uri 解析 URI 并确定路由 * @property CI_User_agent $user_agent 标识浏览代理的平台、浏览器、机器人或移动设备 * @property CI_Validation $validation //死 * @property CI_Xmlrpc $xmlrpc XML-RPC 请求处理程序类 * @property CI_Xmlrpcs $xmlrpcs XML-RPC 服务器类 * @property CI_Zip $zip Zip 压缩类 * @property CI_Javascript $javascript Javascript 类 * @property CI_Jquery $jquery Jquery 类 * @property CI_Utf8 $utf8 提供对 UTF-8 环境的支持 * @property CI_Security $security 安全类、xss、csrf 等... */ 类 CI_Controller{} /** * @property CI_DB_active_record $db 这是独立于平台的基础 Active Record 实现类。 * @property CI_DB_forge $dbforge 数据库实用程序类 * @property CI_Benchmark $benchmark 这个类可以让你标记点并计算它们之间的时间差。
还可以显示内存消耗。 * @property CI_Calendar $calendar 这个类可以创建日历 * @property CI_Cart $cart 购物车类 * @property CI_Config $config 此类包含使配置文件能够被管理的函数 * @property CI_Controller $controller 这个类对象是每个库所在的超类。
CodeIgniter 将被分配到。 * @property CI_Email $email 允许使用 Mail、Sendmail 或 SMTP 发送电子邮件。 * @property CI_Encrypt $encrypt 使用 XOR Hashing 和 Mcrypt 提供双向密钥编码 * @property CI_Exceptions $exceptions 异常类 * @property CI_Form_validation $form_validation 表单验证类 * @property CI_Ftp $ftp FTP 类 * @property CI_Hooks $hooks 提供一种机制来扩展基本系统而无需黑客攻击。 * @property CI_Image_lib $image_lib 图像处理类 * @property CI_Input $input 预处理全局输入数据以确保安全 * @property CI_Lang $lang 语言类 * @property CI_Loader $load 加载视图和文件 * @property CI_Log $log 日志记录类 * @property CI_Model $model CodeIgniter 模型类 * @property CI_Output $output 负责将最终输出发送到浏览器 * @property CI_Pagination $pagination 分页类 * @property CI_Parser $parser 解析指定模板视图中包含的伪变量,
用第二个参数中的数据替换它们 * @property CI_Profiler $profiler 此类使您能够显示基准、查询和其他数据
以帮助调试和优化。 * @property CI_Router $router 解析 URI 并确定路由 * @property CI_Session $session 会话类 * @property CI_Sha1 $sha1 使用安全散列算法提供 160 位散列 * @property CI_Table $table HTML 表生成
让您可以手动或从数据库结果对象或数组创建表。 * @property CI_Trackback $trackback Trackback 发送/接收类 * @property CI_Typography $typography 排版类 * @property CI_Unit_test $unit_test 简单测试类 * @property CI_Upload $upload 文件上传类 * @property CI_URI $uri 解析 URI 并确定路由 * @property CI_User_agent $user_agent 标识浏览代理的平台、浏览器、机器人或移动设备 * @property CI_Validation $validation //死 * @property CI_Xmlrpc $xmlrpc XML-RPC 请求处理程序类 * @property CI_Xmlrpcs $xmlrpcs XML-RPC 服务器类 * @property CI_Zip $zip Zip 压缩类 * @property CI_Javascript $javascript Javascript 类 * @property CI_Jquery $jquery Jquery 类 * @property CI_Utf8 $utf8 提供对 UTF-8 环境的支持 * @property CI_Security $security 安全类、xss、csrf 等... */ 类 CI_Model{}

2。在 IntelliJ IDEA 中找到 /system/core/controller.php/system/core/model.php 并右键单击->标记为纯文本。

3。完毕!它工作得很好,没有更多的错误错误和代码完成!

【讨论】:

  • 可能应该做一些更好的搜索。将此作为答案发布,希望能帮助其他遇到此问题的人(搜索它会发现很多问题但没有答案)。
  • 它对我不起作用我收到诸如未定义函数 form_open() 等错误
【解决方案2】:

这是对我有用的解决方案:https://github.com/Stunt/Codeigniter-autocomplete/

我正在使用 phpStorm,但我想它可以与 IDEA 一起使用。

无需将文件标记为纯文本。只需将 autocomplete.php 文件放入 application/config 文件夹即可。我怀疑 github 上的链接会变坏,但以防万一这是文件的内容。

<?php
// help IDE(s) support Codeigniter 2.0
/**
 * @property CI_DB_active_record $db
 * @property CI_DB_forge $dbforge
 * @property CI_Benchmark $benchmark
 * @property CI_Calendar $calendar
 * @property CI_Cart $cart
 * @property CI_Config $config
 * @property CI_Controller $controller
 * @property CI_Email $email
 * @property CI_Encrypt $encrypt
 * @property CI_Exceptions $exceptions
 * @property CI_Form_validation $form_validation
 * @property CI_Ftp $ftp
 * @property CI_Hooks $hooks
 * @property CI_Image_lib $image_lib
 * @property CI_Input $input
 * @property CI_Language $language
 * @property CI_Loader $load
 * @property CI_Log $log
 * @property CI_Model $model
 * @property CI_Output $output
 * @property CI_Pagination $pagination
 * @property CI_Parser $parser
 * @property CI_Profiler $profiler
 * @property CI_Router $router
 * @property CI_Session $session
 * @property CI_Sha1 $sha1
 * @property CI_Table $table
 * @property CI_Trackback $trackback
 * @property CI_Typography $typography
 * @property CI_Unit_test $unit_test
 * @property CI_Upload $upload
 * @property CI_URI $uri
 * @property CI_User_agent $user_agent
 * @property CI_Validation $validation
 * @property CI_Xmlrpc $xmlrpc
 * @property CI_Xmlrpcs $xmlrpcs
 * @property CI_Zip $zip
 *
 *
 *
 * These are samples entries to make my own functions work. 
 * Remove these and add you custom ones.
 * @property Tank_auth $tank_auth
 * @property Users_model $users_model
 * @property Firms_model $firms_model
 * @property Firms_model_master $firms_model_master
 *
 *
 */
class CI_Controller {};
class MY_Controller extends CI_Controller {};
/**
 * @property CI_DB_active_record $db
 * @property CI_DB_forge $dbforge
 * @property CI_Config $config
 * @property CI_Loader $load
 * @property CI_Session $session
 */
class CI_Model {};
/* End of file autocomplete.php */
/* Location: ./application/config/autocomplete.php */
?>

CIv3 更新:如果您使用的是 CodeIgniter V 3.x,请改用它。

<?php
/**
 * @property CI_DB_query_builder|CI_DB_postgre_driver $db              This is the platform-independent base Active Record implementation class.
 * @property CI_DB_forge $dbforge                 Database Utility Class
 * @property CI_Benchmark $benchmark              This class enables you to mark points and calculate the time difference between them.<br />  Memory consumption can also be displayed.
 * @property CI_Calendar $calendar                This class enables the creation of calendars
 * @property CI_Cart $cart                        Shopping Cart Class
 * @property CI_Config $config                    This class contains functions that enable config files to be managed
 * @property CI_Controller $controller            This class object is the super class that every library in.<br />CodeIgniter will be assigned to.
 * @property CI_Email $email                      Permits email to be sent using Mail, Sendmail, or SMTP.
 * @property CI_Encrypt $encrypt                  Provides two-way keyed encoding using XOR Hashing and Mcrypt
 * @property CI_Exceptions $exceptions            Exceptions Class
 * @property CI_Form_validation $form_validation  Form Validation Class
 * @property CI_Ftp $ftp                          FTP Class
 * @property CI_Hooks $hooks                      Provides a mechanism to extend the base system without hacking.
 * @property CI_Image_lib $image_lib              Image Manipulation class
 * @property CI_Input $input                      Pre-processes global input data for security
 * @property CI_Lang $lang                        Language Class
 * @property CI_Loader $load                      Loads views and files
 * @property CI_Log $log                          Logging Class
 * @property CI_Model $model                      CodeIgniter Model Class
 * @property CI_Output $output                    Responsible for sending final output to browser
 * @property CI_Pagination $pagination            Pagination Class
 * @property CI_Parser $parser                    Parses pseudo-variables contained in the specified template view,<br />replacing them with the data in the second param
 * @property CI_Profiler $profiler                This class enables you to display benchmark, query, and other data<br />in order to help with debugging and optimization.
 * @property CI_Router $router                    Parses URIs and determines routing
 * @property CI_Session $session                  Session Class
 * @property CI_Encryption $encryption            The Encryption Library provides two-way data encryption
 * @property CI_Table $table                      HTML table generation<br />Lets you create tables manually or from database result objects, or arrays.
 * @property CI_Trackback $trackback              Trackback Sending/Receiving Class
 * @property CI_Typography $typography            Typography Class
 * @property CI_Unit_test $unit_test              Simple testing class
 * @property CI_Upload $upload                    File Uploading Class
 * @property CI_URI $uri                          Parses URIs and determines routing
 * @property CI_User_agent $user_agent            Identifies the platform, browser, robot, or mobile devise of the browsing agent
 * @property CI_Form_validation $validation
 * @property CI_Xmlrpc $xmlrpc                    XML-RPC request handler class
 * @property CI_Xmlrpcs $xmlrpcs                  XML-RPC server class
 * @property CI_Zip $zip                          Zip Compression Class
 * @property CI_Javascript $javascript            Javascript Class
 * @property CI_Jquery $jquery                    Jquery Class
 * @property CI_Utf8 $utf8                        Provides support for UTF-8 environments
 * @property CI_Security $security                Security Class, xss, csrf, etc...
 * @property Tank_auth $tank_auth
 *
 */
class CI_Controller{}
class MY_Controller extends CI_Controller {};
/**
 * @property CI_DB_query_builder|CI_DB_postgre_driver $db              This is the platform-independent base Active Record implementation class.
 * @property CI_DB_forge $dbforge                 Database Utility Class
 * @property CI_Benchmark $benchmark              This class enables you to mark points and calculate the time difference between them.<br />  Memory consumption can also be displayed.
 * @property CI_Calendar $calendar                This class enables the creation of calendars
 * @property CI_Cart $cart                        Shopping Cart Class
 * @property CI_Config $config                    This class contains functions that enable config files to be managed
 * @property CI_Controller $controller            This class object is the super class that every library in.<br />CodeIgniter will be assigned to.
 * @property CI_Email $email                      Permits email to be sent using Mail, Sendmail, or SMTP.
 * @property CI_Encrypt $encrypt                  Provides two-way keyed encoding using XOR Hashing and Mcrypt
 * @property CI_Exceptions $exceptions            Exceptions Class
 * @property CI_Form_validation $form_validation  Form Validation Class
 * @property CI_Ftp $ftp                          FTP Class
 * @property CI_Hooks $hooks                      Provides a mechanism to extend the base system without hacking.
 * @property CI_Image_lib $image_lib              Image Manipulation class
 * @property CI_Input $input                      Pre-processes global input data for security
 * @property CI_Lang $lang                        Language Class
 * @property CI_Loader $load                      Loads views and files
 * @property CI_Log $log                          Logging Class
 * @property CI_Model $model                      CodeIgniter Model Class
 * @property CI_Output $output                    Responsible for sending final output to browser
 * @property CI_Pagination $pagination            Pagination Class
 * @property CI_Parser $parser                    Parses pseudo-variables contained in the specified template view,<br />replacing them with the data in the second param
 * @property CI_Profiler $profiler                This class enables you to display benchmark, query, and other data<br />in order to help with debugging and optimization.
 * @property CI_Router $router                    Parses URIs and determines routing
 * @property CI_Session $session                  Session Class
 * @property CI_Encryption $encryption            The Encryption Library provides two-way data encryption
 * @property CI_Table $table                      HTML table generation<br />Lets you create tables manually or from database result objects, or arrays.
 * @property CI_Trackback $trackback              Trackback Sending/Receiving Class
 * @property CI_Typography $typography            Typography Class
 * @property CI_Unit_test $unit_test              Simple testing class
 * @property CI_Upload $upload                    File Uploading Class
 * @property CI_URI $uri                          Parses URIs and determines routing
 * @property CI_User_agent $user_agent            Identifies the platform, browser, robot, or mobile devise of the browsing agent
 * @property CI_Form_validation $validation
 * @property CI_Xmlrpc $xmlrpc                    XML-RPC request handler class
 * @property CI_Xmlrpcs $xmlrpcs                  XML-RPC server class
 * @property CI_Zip $zip                          Zip Compression Class
 * @property CI_Javascript $javascript            Javascript Class
 * @property CI_Jquery $jquery                    Jquery Class
 * @property CI_Utf8 $utf8                        Provides support for UTF-8 environments
 * @property CI_Security $security                Security Class, xss, csrf, etc...
 * @property Tank_auth $tank_auth
 */
class CI_Model {};

我不能把这一切归功于我。我找到了很多,但不记得在哪里。我确实需要添加一些以使其完整。

【讨论】:

  • 它是否适用于内置 CI 功能?如果是这样,它工作正常。要使其与您的自定义函数一起使用,请修改下面的条目: * 这些是使我自己的函数工作的示例条目。 * 删除这些并添加您自定义的。
  • 在 CI 3 中没有文件 CI_DB_active_record.php 那么如何处理这些问题......
  • 通过这种方式,使用简单编辑器比使用高级/重型 IDE...
  • @user4706838 我发布了一个与 CI 3 配合使用的新文件
  • 您有什么要添加的...?那么为什么你从 DC_ 的答案中复制/粘贴呢? stackoverflow.com/a/15425005/1429432 ?没有,模仿者。
猜你喜欢
  • 2013-12-28
  • 2014-10-19
  • 2013-01-05
  • 2013-02-02
  • 1970-01-01
  • 1970-01-01
  • 2013-02-12
  • 2015-03-17
  • 1970-01-01
相关资源
最近更新 更多