How to Add AutoComplete to Eclipse/Aptana

This article is also available in the following languages:
By gravyface
In this article I'll show you how to add autocomplete to Eclipse/Aptana for models, components, and helpers. Thanks goes out to schneimi and voidstate's on Google Groups for figuring this trick out.
If you haven't already, create an AppController in your application folder. By default, the file app_controller.php should be created in /your/cake/install/app/

Adding AutoComplete in Controllers for Models and Components


Copy/paste the following lines somewhere in your app_controller.php; when finished, it should look like this:

Controller Class:

<?php 
/**
 * Post Model
 *
 * @var Post
 */
 
var $Post;

/**
 * User Model
 *
 * @var User
 */
 
var $User;

 
/**
 * Group Model
 *
 * @var Group
 */
 
var $Group;
 
 
/**
 * AuthComponent
 *
 * @var AuthComponent
 */
 
var $Auth;
 
 
/**
 * SessionComponent
 *
 * @var SessionComponent
 */
 
var $Session;
 
  
/**
 * RequestHandlerComponent
 *
 * @var RequestHandlerComponent
 */
 
var $RequestHandler;

?>

Substitute my models for your own, obviously.

Now in Eclipse, you should be able to hit CTRL-SPACE after entering $this-> to bring up a selection of model and/or components; ditto for model and/or component methods, properties, etc. Note: make sure you use the window resizer (bottom-right) to stretch out the autocomplete window so you see the full object docs (you'll notice that "parameters" will be cut-off and show "...").

Adding Helper AutoComplete to Views


Create a file called "eclipse_helper.php" (or whatever, it doesn't matter) and put it somewhere in your /app path. Copy/paste the following:

Helper Class:

<?php 
exit();
// auto-complete in views for Helpers
if(false) {
    
$ajax = new AjaxHelper();
    
$cache = new CacheHelper();
    
$form = new FormHelper();
    
$html = new HtmlHelper();
    
$javascript = new JavascriptHelper();
    
$number = new NumberHelper();
    
$session = new SessionHelper();
    
$text = new TextHelper();
    
$time = new TimeHelper();
}
?>

NOTE: if (like me) you have a bad habit of creating files outside of Eclipse, make sure you hit F5 and refresh your project or the view helpers won't work.

Not working? Try closing/re-opening Eclipse.

You're good to go. Have fun!


Comments

  • Posted 03/17/11 07:57:47 PM
    Anyway to get $this->form instead of $form-> helper code completion in Aptana Php?
  • Posted 10/16/09 09:11:53 PM
    For users , who don't use it yet, grab here http://opencakefile.sourceforge.net/
    Open Cake file adds some support of eclipse based IDE's (like aptana and zend, including 7) like "support" for ctp files. By default zend will refuse to save ctp files, as unknown file type. and some other minor improvements :)
  • Posted 09/26/09 08:15:48 PM
    Using this example I got the "$this->" to auto-complete, in xxx_controller.php files, but not much else. I had envisioned that I would have auto-complete in modules like "*.ctp" and others.

    Am I expecting too much from code completion, or do I have things installed wrong. If I am wrong, does anyone have a newbie-simple step-by-step as to how to implement auto-complete in Aptana?

    I am new to CakePHP, and know I would find the auto-complete very useful in learning.

    Thanks!
  • Posted 07/25/09 09:16:17 PM
    Where is app_controller.php?
  • Posted 07/23/09 03:36:22 PM
    Is there any way to make it happen in Zend Studio 5.5?
  • Posted 07/23/09 12:18:02 PM
    but i have to disagree with your choice of using the app controller for it

    just name it
    "code_completion__.php"
    oder whatever

    it will be picked up by IDE anyway
    you could eben put both of them together in one file

Comments are closed for articles over a year old