2013-03-15 161 views
5

我正在使用IntelliJ IDEA 12開發使用CodeIgniter框架的PHP Web應用程序。由於路CI實例化對象和方法,觀念認爲它們不存在時,他們叫:IntelliJ IDEA 12找不到CodeIgniter類,拋出錯誤

enter image description here

正如你所看到的,我得到的每一個笨類/方法下的那些煩人的橘子squigglies我嘗試使用。

這裏是爲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中做了同樣的事情。

+0

使用'Aptana'。它非常適合'Codeigniter'。 – 2013-03-15 04:36:58

+1

@YogeshSuthar我會研究它,但我更喜歡使CI與IntelliJ IDEA一起工作的解決方案。 – 2013-03-15 04:38:41

+0

谷歌搜索顯示你不是唯一的問題。我使用Sublime Text,它非常適合CI--甚至還有一些由第三方創建的代碼完成插件。 – 2013-03-15 04:49:37

回答

8

我通過以下this guide解決了這個問題。它的意思是PHPStorm,但也適用於IntelliJ IDEA(也可能是WebStorm!)。實際上這很簡單。基本概述:

  1. 在我的項目根目錄中保存了以下PHP代碼。它基本上只是一個PHPDoc的評論:
 
    <?php die('This file is not really here!'); 

    /** 
    * ------------- DO NOT UPLOAD THIS FILE TO LIVE SERVER --------------------- 
    * 
    * Implements code completion for CodeIgniter in phpStorm 
    * phpStorm indexes all class constructs, so if this file is in the project it will be loaded. 
    * ------------------------------------------------------------------- 
    * Drop the following file into a CI project in phpStorm 
    * You can put it in the project root and phpStorm will load it. 
    * (If phpStorm doesn't load it, try closing the project and re-opening it) 
    * 
    * Under system/core/ 
    * Right click on Controller.php and set Mark as Plain Text 
    * Do the same for Model.php 
    * ------------------------------------------------------------------- 
    * This way there is no editing of CI core files for this simple layer of code completion. 
    * 
    * PHP version 5 
    * 
    * LICENSE: GPL http://www.gnu.org/copyleft/gpl.html 
    * 
    * Created 1/28/12, 11:06 PM 
    * 
    * @category 
    * @package CodeIgniter CI_phpStorm.php 
    * @author  Jeff Behnke 
    * @copyright 2009-11 Valid-Webs.com 
    * @license GPL http://www.gnu.org/copyleft/gpl.html 
    * @version 2012.01.28 
    */ 

    /** 
    * @property CI_DB_active_record $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.
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.
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,
replacing them with the data in the second param * @property CI_Profiler $profiler This class enables you to display benchmark, query, and other data
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_Sha1 $sha1 Provides 160 bit hashing using The Secure Hash Algorithm * @property CI_Table $table HTML table generation
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_Validation $validation //dead * @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... */ class CI_Controller{} /** * @property CI_DB_active_record $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.
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.
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,
replacing them with the data in the second param * @property CI_Profiler $profiler This class enables you to display benchmark, query, and other data
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_Sha1 $sha1 Provides 160 bit hashing using The Secure Hash Algorithm * @property CI_Table $table HTML table generation
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_Validation $validation //dead * @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... */ class CI_Model{}

2.發現/system/core/controller.php/system/core/model.php IntelliJ IDEA的和右clicked->標記爲純文本的內部。

3.完成!它工作的很棒,不會出現錯誤和代碼完成!

enter image description here

+0

可能應該做一些更好的搜索。發佈此作爲答案,希望可以幫助任何人有這個問題(搜索它揭示了很多問題,沒有答案)。 – 2013-03-15 04:54:29

+0

它不適用於我我得到錯誤,如未定義的函數form_open()等 – 2015-07-21 15:38:15

0

這是爲我工作的解決方案:https://github.com/Stunt/Codeigniter-autocomplete/

我使用phpStorm但我想它會與IDEA工作。

無需將文件標記爲純文本。只需將autocomplete.php文件放入應用程序/配置文件夾中即可。我懷疑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 {}; 

我不能承認所有這一切。我發現了很多這些但不記得在哪裏。我確實需要添加一些才能完成。

+0

它不工作對我而言我使用CI-3任何進一步的建議或幫助... – 2015-07-21 15:26:13

+0

我得到錯誤,如未定義的函數form_open ()等... – 2015-07-21 15:28:37

+0

它是否適用於內置CI功能?如果是這樣,它工作正常。爲了使它與您的自定義函數一起工作,請修改以下條目:*這些是樣本條目,以使我自己的函數可以正常工作。 *刪除這些並添加您自定義的。 – 2015-07-22 21:37:41

相關問題