Setting up Eclipse to work with Cake

By Michael McAndrew aka "MilkyJoe"
You’re on the quest for painless PHP development. You’re using Cake and considering the goodness of Eclipse. Two great first steps.

All you need now is a little help getting to know Eclipse and configuring it for CakePHP. This tutorial gathers information already out there, adds a bit more, and puts in all in one place.
This tutorial is based on a standard setup.

  • A recent stable build of Eclipse PHP Development Tools (3.2.100)
  • Standard CakePHP install (in C:\xampp\htdocs\cake) 1.1 or 1.2
  • Standard XAMPP install (in C:\xampp)
  • Windows XP.

There is a lot more that could be covered. If you can fill the gaps or suggest how it could be improved, that would be great.

Why use eclipse with CakePHP?


Firstly, it is open source with a huge and healthy ecosystem surrounding it. That means (if you believe the hype) that with the right choice of plug-ins, you'll satisfy all your development needs with just one program.

Secondly, it is big and powerful, but very easy to use ... honestly. Software this simple must be a lot of brain ache to create.

Finding and installing Eclipse for PHP


Whilst Eclipse is a generic IDE, there are a few flavours of Eclipse made specifically for PHP development. The one I use is called the PHP Development Tools (PDT) project. It�s homepage is http://www.eclipse.org/pdt/.

According to the PDT site, the �PDT All-in-One" package �includes the complete set of software to start using PDT immediately. This package already has PDT combined with the complete set of prerequisites - you will not need anything else." You can�t argue with that. I downloaded the latest stable build for Windows from http://download.eclipse.org/tools/pdt/downloads/.

Installing eclipse is very easy. There is no install shield or wizard. All you do is unzip it, and put it where you want it. In case you want to be just like me, put it in your program files directory, and add a shortcut to eclipse.exe in �All Programs�. Then launch the program. The first time you run it, the first question you will ask yourself is probably...

What is the workspace?


The workspace is the place where you store your projects (in this case your CakePHP applications). Essentially, it is a directory on your hard drive. People have different things to say about the workspace, things like: �keep all your projects in the same workspace??, and �use your webroot as your workspace??.

Eclipse asks you to set your workspace the first time you run it.

Defining your workspace


There are no fixed rules, but I would advise you to set your workspace to C:\xampp\htdocs\. If when Eclipse first started, you defined a different workspace, you can define another easily like this:

  1. Go to File > Switch Workspace > Other
  2. In the Workspace field enter "C:\xampp\htdocs\"

What are projects?


Projects are (as you might expect) the applications you are developing. In our case, CakePHP applications - the things that start out life as a copy of your /app folder.

Defining projects


I follow the Cake convention of storing all my CakePHP projects in the Cake root directory (making a copy of /app, renaming it, and changing the constant APP_DIR in /app/webroot/index.php to the name of my directory). You should probably follow this convention as well.

Define each Cake application as a project like this:

  1. File > New > PHP Project.
  2. In the Project name field, type your Cake applications name.
  3. In Project contents, uncheck use default, and add the directory for your project (something like: C:\xampp\htdocs\cake\project_name).

Now you can see the project in the PHP explorer view on the left hand side of the screen . Notice that you can expand files in this view to explore and look at their structure � very cool, but in comparison to what we are about to do, only slightly cool.

Now we'll link this project to the cake core. This means you'll be able to use classes, constants in Eclipse's auto-complete. You'll also have access to your cake core files - a handy reference.

First, define the Cake core as a project:

  1. File > New > PHP Project.
  2. In the Project name field, type 'Cake', or something similar.
  3. In Project contents, uncheck use default, and add (C:\xampp\htdocs\cake\cake).

Then link the Cake core application this to our application:
  1. In the PHP explorer window, right click on the application and choose Configure Include Path.
  2. From the projects tab, select Add
  3. Then tick the Cake checkbox. (make sure you haven�t closed the Cake project otherwise it won�t be available to check).

Now try it out. Open or create a controller for your application and have a look at the Outline view. The class inheritance is all there. Sweeb! And code completion works in the PHP editor (the shortcut is Ctrl+Space). Double sweeb!

Setting up the bake script to work directly from the Eclipse platform


This is a great integration. It works slightly differently depending on what version of Cake you are using.

Cake 1.1


  1. From the menu choose Run > External Tools > Open External Tools Dialogue...
  2. In the left hand side pane, choose Program and then click on the 'New Launch Configuration' button
  3. Name this new configuration something like Bake.
  4. In the main tab...
  5. In the location text field, enter the path to your php.exe. (Mine is C:\xampp\php\php.exe)
  6. In the Working Directory text field, enter the path of the directory containing your bake.php file. (Mine is C:\xampp\htdocs\cake\cake\scripts)
  7. In the Arguments text area add bake.php.
  8. Apply and close the dialogue

Then go to Run > External tools > Organise favourites > Add.
Check bake and click OK

Cake 1.2


  1. Follow the instructions for setting up the CakePHP console on Windows here: http://cakephp.org/screencasts/view/6 and do a little test like Gwoo did to make sure it is working properly. (I had to reset my computer before this worked properly). To be honest, I think you only need to add the php line to the path as we will specify the other path to cake.bat in Eclipse but I�m not sure you might as well.
  2. Back in Eclipse, from the menu choose Run > External Tools > Open External Tools Dialogue...
  3. In the left hand side pane, choose Program and then click on the 'New Launch Configuration' button
  4. Name this new configuration something like Bake.
  5. In the main tab...
  6. In the location text field, enter �${workspace_loc:/Cake/console/cake.bat}??
  7. In the Working Directory text field, enter �${project_loc}?? (the value of ${project_loc} changes depending on what project you are in.
  8. In the Arguments text area add �bake??
  9. Apply and close the dialogue
  10. Then go to Run > External tools > Organise favourites > Add.
  11. Check bake and click OK.

Using the bake script


To bake, click on the run external tool button and choose bake. Or selecting bake from the run menu. If you�re using 1.2 make sure you have selected the project you want to bake for, as this effects the ${project_loc} (see above).

Pretty cool hey? Think back to before you set this up. Coding was like writing on a piece of toilet paper with a leaky fountain pen.

Setting up Eclipse to recognise .thtml or .ctp files


Depending on which version of Cake you are using you will want to set up Eclipse to recognise that the .thtml (1.1) or .ctp(1.2) files used in your views are actually PHP files. This will give you syntax colouring and (limited) code completion.
  1. Window > Preferences > General > Content types...
  2. Under content types expand the tree to text > PHP content type
  3. In file associations, click add...
  4. Add *.thtml (1.1) or *.ctp(1.2)

Then go in the same preferences dialogue box...
  1. From the tree, choose Editors > File Associations
  2. Add the file type *.thtml (1.1) or *.ctp(1.2).
  3. In Associated Editors:, select the PHP Editor and click Default.

Adding support for Subversion using Subclipse


This tutorial assumes you already have a repository. I think it is worth having one - versioning makes development a lot easier. For a comprehensive introduction to SVN (and if you haven't had one, you do need one) I recommend you read the online SVN book at http://svnbook.org or http://svnbook.red-bean.com/, download SVN from http://subversion.tigris.org/, and tortoise SVN from http://tortoisesvn.tigris.org/.

To install the Subclipse plugin:
  1. Help > Software updates > find and install > Search for new features to install
  2. Click on new remote site. In the name field, enter "Subclipse". In the URL enter "http://subclipse.tigris.org/update_1.2.x". Click OK (note, version 1.2 of subclipse is for Eclipse 3.2 and above. For other versions see the subclipse installation page below)
  3. Back in the install box, Subclipse should be checked. (If it isn't, check it.)
  4. Click on finish
  5. In the next screen, expand the Eclipse tree and select the Subclipse plugin and click next, agree to the license and click finish.
  6. Once they've downloaded, you'll need to click on Install again, to verify that you are installing an "unsigned feature".
  7. Then it's probably worth restarting, as it advises.
  8. Note: Installation instructions also available here: http://subclipse.tigris.org/install.html)

Adding a repository


Before you use a repository (that you have made using SVN or tortoise SVN), you need to define it in Eclipse:
  1. Switch to the SVN Repository Exploring perspective. (Window > Open perspective > Other... > SVN repository exploring.
  2. In the SVN repository view, right click and choose New >Repository location
  3. Type in the location of your repository in the style of a URL. (it might look something like this file:///C:/svn/mycakeapp)
  4. That's it. Your repository should now be visible in the SVN repository view.

What you do next depends on if you have used SVN before, if you have your projects set up in SVN already or not, and how you have your SVN repository set up. I won't go into all the details but to start you off.

To add a project to SVN


  1. Right click on the prject and choose Team > Share project...
  2. Choose SVN as your repository type
  3. Then choose where you want to add this project, etc.

To check out an already existing project from SVN:
  1. Choose File > New > Project... Checkout Projects from SVN
  2. Select the folder you want to check out, etc.

If you've used SVN before, that should be enough. If you haven't, you might have to play around with it a bit to really understand it.

Accessing your database


I'm not sure of the advantages of administering your cake databases from within Eclipse, indeed, one of the principles of Cake is to minimise direct access to the database. The only SQL tasks you do regularly are creating and altering tables - pretty simple.

And when it comes to MySQL, the eclipse database plugins are as comprehensive or as easy to use as phpMyAdmin and and they don't integrate with other aspects of Eclipse in any way that is useful to Cake (though I would like to be corrected on these points). I started trying the data tools platform, then moved to Quantum DB, then went back to just using phpMyAdmin.

If you want to keep all development inside Eclipse, phpMyAdmin looks pretty cool running on the Eclipse internal browser ;-)

If you want to set up a database plug in, you could choose QuantumDB and follow the instructions below.

Install the QuantumDB plugin


  1. Help > Software updates > find and install > Search for new features to install
  2. Click on new remote site. In the name field, enter "QuantumDB". In the URL enter "http://quantum.sourceforge.net/update-site"
  3. Back in the install box, QuantumDB should be checked. (If it isn't, check it.)
  4. Click on finish
  5. In the next box, select the entire QuantumDB tree and click next
  6. Agree to the license and click next, then finish, then Install all

Configure connection to MySQL database


  1. Help > Software updates > find and install > Search for new features to install
  2. Click on new remote site. In the name field, enter "QuantumDB". In the URL enter "http://quantum.sourceforge.net/update-site"
  3. Back in the install box, QuantumDB should be checked. (If it isn't, check it.)
  4. Click on finish
  5. In the next box, select the entire QuantumDB tree and click next
  6. Agree to the license and click next, then finish, then Install all

Configure access to your database with QuantumDB


Once it has installed, you need to download the latest MySQL JDBC (Java DataBase Connectivity) driver. The best place to find this is on the MySQL website here http://dev.mysql.com/downloads/connector/j/.
  1. Unzip the connector and put the mysql-connector-java-x.x.x-bin.jar file in a suitable folder. Like "C:\Program Files\Eclipse\plugins"
  2. Now, in the QuantumDB perspective, right click in the database bookmarks view and select New Bookmark
  3. Then choose Add Driver > Add External jar and navigate to the connector (we put it in "C:\Program Files\Eclipse\plugins").
  4. Back in the New JDBC Driver page, click Browse and select the "com.mysql.jdbc.Driver" class name. The type should change to MySQL. Change to MySQL if it isn't and click finish.
  5. Then choose the new driver and click next. Then fill in your database login details, click next and choose a suitable name for the bookmark

Now your bookmark is visible in the Database Bookmarks view, and you can run queries using the Quantum SQL Queries View.

What else



I hope to add FTP/ANT support once I've figured out a nice config. Anyone want to help?

I hope that is a good jumping off point for using CakePHP with Eclipse. It is only one of many ways you could set it up. If you know of a better config, or have any other suggestions/additions/corrections, please add them.

Thanks to everyone who has unknowingly helped me in writing this document through their blogs, google group postings, IRC chats and telepathic communications.

Comments 485

CakePHP team comments Author comments

Comment

1 code completion

most wanted I think for cakephp and eclipse would be a plugin
that would make code completion work for example on model methods I call in controller and so on.

ie.
$this->MyModel->[code completion jumps in]

does anyone have a glue how to make this work?
posted Fri, Jul 27th 2007, 03:45 by emilk

Comment

2 Ant Build Script SVN FTP

I use Ant Build script, SVN, and FTP to deploy my application using Eclipse.
posted Sun, Jul 29th 2007, 09:37 by Francis

Comment

3 Re Ant Build Script SVN FTP

Hi Francis,

That sounds pretty useful! I've just learnt how to use SVN and am pretty happy about that. The ANT and FTP stuff sounds massively useful too - i wonder if we could have a chat about it? I would love to add that side of things to this tutorial.

My email is michaelmcandrew AT gmail.com.
posted Sun, Jul 29th 2007, 18:53 by Michael McAndrew

Comment

4 More please

+1 on the ANT / SVN / FTP deployment script.

I've been playing with (unsuccessfully so far) is integrating Eclipse with Trac, might be worth looking into!

I've also been playing with the templates for code completion, very handy for generating the larger phpdoc comments (like the ones at the top of each object).

IMHO this tutorial is well overdue.
posted Mon, Jul 30th 2007, 01:25 by Alex McFadyen

Comment

5 ANT Build Script

Hi Michael, I have added you to my gmail chat contacts, BTW my real name is Francis Verana.

Below is the build script, I am not a good writer that's why I don't submit tutorials. :)

The basic concept is to store a VERSION.txt in your web server containing the last Revision number. When the build script runs it fetches this version text and extract the revision number and compares it to your trunk revision number, fetches the changed/modified/added files, I know there are some quirks in the build script but it works for me most of the time and is a great time saver. I have removed domain name so change it first and it uses lots of temporary files. I had a hardtime making the in memory temp files of ant to work.

<?xml version="1.0" encoding="UTF-8"?>
<project name= "Project Build Script" default="startPublish" basedir=".">
    <buildnumber file="build.number"/>

    <property name="remoteDir" value="/public_html/predictor" />
    <property name="svnRoot" value="/trunk/PredictorExam/" />
    <property name="svnServer" value="https://SVNServerDomain.com/svn/trunk/PredictorExam" />

    <property name="ftpSite" value="ftp.YourDomainHere.com"/>
    <!-- property name="ftpSite" value="192.168.1.200" / -->

    <property name="versionTextURL" value="http://www.YourDomainHere.com/VERSION.txt" />
    <!--property name="versionTextURL" value="http://192.168.1.200/~aplusnur/VERSION.txt" /-->
    <property name="ftpUsername" value="ftpusername" />
    <property name="ftpPassword" value="ftppassword" />

    <taskdef resource="svntask.properties" />

    <target name="startPublish">
        <antcall target="fetchServerVersion" />
        <antcall target="generateModifiedFileList" />
        <antcall target="cleanFileList" />
        <antcall target="startFTP" />
    </target>

    <!-- fetch the VERSION.txt from the web server and generate a new VERSION.txt -->
    <target name="fetchServerVersion">
        <get src="${versionTextURL}"
             dest="/tmp/serverVersion"
             verbose="true"
             usetimestamp="true" />
        <exec executable="svn" output="VERSION.txt">
            <arg line="log -rHEAD ${svnServer}" />
        </exec>
    </target>

    <target name="generateModifiedFileList">
        <loadfile property="serverVersion" srcfile="/tmp/serverVersion">
            <filterchain>
                <headfilter lines="1" skip="1"/>
                <tokenfilter delimoutput="">
                    <replaceregex pattern="\s\|\s.*" replace=""/>
                </tokenfilter>
            </filterchain>
        </loadfile>
    <echo message="Server Revision No: ${serverVersion}"/>
    <!-- get a list of files modified from serverVersion to HEAD -->
        <exec executable="svn" output="/tmp/fileList.txt">
           <arg line= "log -vq -${serverVersion}:HEAD ${svnServer}" />
        </exec>
    </target>

    <!-- clean the list possible with output redirection (ant is powerful) but this for now -->
    <target name="cleanFileList">
        <copy file="/tmp/fileList.txt"
              tofile="/tmp/modifiedFileList.txt"
              overwrite="true" >
            <filterchain>
                <linecontainsregexp>
                  <regexp pattern=" {3}[AMDR]"/>
                </linecontainsregexp>
                <tokenfilter>
                    <replaceregex pattern=" {3}[AMDR] ${svnRoot}" replace="" />
                </tokenfilter>
            </filterchain>
        </copy>
        <exec executable="sort" output="/tmp/tmp1">
            <arg file="/tmp/modifiedFileList.txt" />
        </exec>
        <exec executable="uniq" output="/tmp/tmp3">
            <arg file="/tmp/tmp1" />
        </exec>
    </target>

    <target name="generateChangedFileList">
        <exec executable="egrep" output="/tmp/changedFileList.txt">
            <arg value="^ {3}[AMDR]" />
            <arg file="/tmp/SVNlog.txt" />
        </exec>
        <exec executable="cut" output="/tmp/cleanFileList.txt">
            <arg value="-c6-" />
            <arg file="/tmp/changedFileList.txt" />
        </exec>
        <exec executable="sort" output="/tmp/sortedFileList.txt">
            <arg file="/tmp/cleanFileList.txt" />
        </exec>
        <exec executable="uniq" output="/tmp/fileList.txt">
            <arg file="/tmp/cleanFileList.txt" />
        </exec>
    </target>

    <!-- perform any configuration changes specific to host to files before deployment -->
    <target name="fixConfig">
        <replace file="app/config/core.php">
            <replacetoken><![CDATA[define('DEBUG', 3)]]></replacetoken>
            <replacevalue><![CDATA[define('DEBUG', 0)]]></replacevalue>
        </replace>
    </target>

    <target name="encryptSource">
        <exec executable="${zendencoder}" >
          <arg line="--quiet --recursive --ignore-errors --short-tags on --asp-tags off --optimizations 1023 --no-default-extensions --include-ext php --include-ext thtml --no-header --ignore 'CVS' --ignore 'tags.ini.php' --delete-source 'c:\tmp\powerlife'" />
        </exec>
    </target>


    <target name="newCakeApp">
    </target>

    <target name="startFTP">
        <ftp server="${ftpSite}"
               userid="${ftpUsername}"
               password="${ftpPassword}"
               timediffauto="true"
               remotedir="${remoteDir}"
               action="send"
               verbose="yes"
               binary="yes">
                <fileset dir="." includesfile="/tmp/tmp3">
                </fileset>
        </ftp>
        <!-- upload the VERSION.txt to the web server root -->
        <ftp server="${ftpSite}"
                 userid="${ftpUsername}"
                 password="${ftpPassword}"
                 timediffauto="true"
                 remotedir="/public_html"
                 action="send"
                 verbose="yes"
                 binary="yes">
            <fileset dir="." >
                <include name="VERSION.txt"/>
            </fileset>
        </ftp>
    </target>

    <target name="uploadChanges">
    </target>

    <target name="removeDeleted">
    </target>

    <target name="cleanUp">
        <delete dir="/tmp/predictor" />
    </target>
</project>


Felix Geisendörfer aka the_undefined has a bake console script that uses the same concept, but he hates ANT, I think ;)

below are links to his blog articles that can also help in other alternatives:
http://www.thinkingphp.org/2006/10/10/ant-sucks-for-ftp-deployment-what-alternatives-do-we-have/
http://www.thinkingphp.org/2006/11/22/release-early-release-often-a-svnftp-deployment-task/
posted Mon, Jul 30th 2007, 01:55 by Francis

Comment

6 php eclipse

most wanted I think for cakephp and eclipse would be a plugin
that would make code completion work for example on model methods I call in controller and so on.

ie.
$this->MyModel->[code completion jumps in]

does anyone have a glue how to make this work?


I use PHP Eclipse -> http://www.phpeclipse.de/
It has code completion and syntax highlighting.
posted Mon, Jul 30th 2007, 03:20 by Lorenzo Moretti

Comment

7 Mylyn

I've been playing with (unsuccessfully so far) is integrating Eclipse with Trac, might be worth looking into!

You might want to look into Mylyn (used to be "mylar"). Integrates well with pdt, svn and trac

http://www.eclipse.org/mylyn/
posted Mon, Jul 30th 2007, 22:58 by Mark Armendariz

Comment

8 EasyEclipse

EasyEclipse are distributions : Eclipse + plugins
there's a ditrib for PHP : http://www.easyeclipse.org/site/distributions/php.html

if integrates plugins as phpeclipse, subclipse (svn), html tidy, web tools editor... support highlighting and completion
posted Wed, Aug 1st 2007, 01:30 by Dia

Comment

9 Eclipse Buggyness

Here is the weird thing about Eclipse that I cannot figure out. I use Eclipse at work with CakePHP and I do not get the code completion but, at home I do. The only difference is this: My Eclipse at work has been updated to the latest version while, my Eclipse at home was a fresh install. (3.3)
Both say "Europa" under Eclipse on the loading window.

I think I will do a bit more testing but, I don't think it is the way they are set up or the preferences as they have the same.

Two bad points about my Eclipse at home:
1. Although I get code completion for CakePHP, I get every single function that Cake offers, instead of getting the functions just for that Model or Controller. I'm guessing the extends have something to do with it ;)

2. Cake has to be in the same folder to get the code completion. Even if you reference you separate cake project, folder or whatever, Cake has to be in the same project.

most wanted I think for cakephp and eclipse would be a plugin
that would make code completion work for example on model methods I call in controller and so on.

ie.
$this->MyModel->[code completion jumps in]

does anyone have a glue how to make this work?


I use PHP Eclipse -> http://www.phpeclipse.de/
It has code completion and syntax highlighting.
posted Thu, Aug 9th 2007, 12:18 by Christopher E. Franklin

Comment

10 Aptana

I'd also check out Aptana if you were looking for a new editor/IDE to develop with. It is Eclipse based so works exactly the same way, only looks much nicer =) ...well, that AND it has more features for javascript and html than most other IDEs which is probably where you want to be when making cake apps. Since a lot of Javascript/Ajax gets used in cake apps, it's handy.

The code coloring is great and fully customizable. It does not have code hinting for PHP yet and it does have its quirks, but it's under active development.

It is by far the best version of Eclipse I've seen.

I use trac with it very easily in fact. The simplicity of right clicking a project > team > commit or update or syncronize, etc. is simply beautiful.

If you're a windows user, you're in luck as that version of Aptana has a Firefox preview option. Basically, everything you need can be done from within the IDE. Minus Photoshop =) Though there is a plugin to view images.

One thing I wish you could do with the IDEs is preview your cake app. Unfortunately previewing a thtml file naturally just shows the code. There are web browser plugins for Eclipse that may let you do it somewhere I guess but that's as manual as using a browser...I'd like to just "preview" a view and have it know the url automatically.
posted Fri, Aug 10th 2007, 11:42 by Tom Maiaroto

Comment

11 Code completion

most wanted I think for cakephp and eclipse would be a plugin
that would make code completion work for example on model methods I call in controller and so on.

ie.
$this->MyModel->[code completion jumps in]

does anyone have a glue how to make this work?

Think a bit on how can a program such as PDT be aware of the type of $this->MyModel var? It's impossible 'cause the type can be anything and it's set somewhere in the Cake's code.

That's why in my controllers I use $uses = array(); and prefer to load any Models lazily, only those that I need in the action.
So, use this in the action:

loadModel('Model');
$this->Model = new Model();
// now you will get your code completion on $this->Model


Later.
posted Sun, Aug 12th 2007, 07:28 by zeRUS

Comment

12 Re Eclipse Buggyness



Two bad points about my Eclipse at home:
1. Although I get code completion for CakePHP, I get every single function that Cake offers, instead of getting the functions just for that Model or Controller. I'm guessing the extends have something to do with it ;)

2. Cake has to be in the same folder to get the code completion. Even if you reference you separate cake project, folder or whatever, Cake has to be in the same project.


Hi there,

About the first point - i don't think it is to do with the extenders as any function is available anywhere. finer grain control would only be avaiable with a cake specific code completion plug in, i think - until that day. having every single function available isn't the worst thing in the world though i guess there are some that don't make sense, like accessing controller functions in the model.

About your second point - i don't have cake folders in my applications - i just reference them as projects - and code completion works for me - you do have to have the cake project open - maybe that is problem? Also, I use Eclipse 3.2.100

posted Tue, Aug 14th 2007, 05:42 by Michael McAndrew

Comment

13 Re Code completion

Think a bit on how can a program such as PDT be aware of the type of $this->MyModel var? It's impossible 'cause the type can be anything and it's set somewhere in the Cake's code.

Nothing is impossible ;)

I think that is one of points at which PDT stops and the Cake Eclipse plugin starts. Parsing the app directory for files like the model definitions and controllers to see what helpers, models, components are available where.

posted Tue, Aug 14th 2007, 05:48 by Michael McAndrew

Comment

14 Still Buggy



Two bad points about my Eclipse at home:
1. Although I get code completion for CakePHP, I get every single function that Cake offers, instead of getting the functions just for that Model or Controller. I'm guessing the extends have something to do with it ;)

2. Cake has to be in the same folder to get the code completion. Even if you reference you separate cake project, folder or whatever, Cake has to be in the same project.


Hi there,

About the first point - i don't think it is to do with the extenders as any function is available anywhere. finer grain control would only be avaiable with a cake specific code completion plug in, i think - until that day. having every single function available isn't the worst thing in the world though i guess there are some that don't make sense, like accessing controller functions in the model.

About your second point - i don't have cake folders in my applications - i just reference them as projects - and code completion works for me - you do have to have the cake project open - maybe that is problem? Also, I use Eclipse 3.2.100



LOL, this is the buggyness I am talking about. I just re-installed both sets of eclipse here at work and at home. I cleared out all the user settings I could find. At least, now, here at work, I get the code completion. Using PHPEclipse, not the PDT project on Eclipse.org.

I tried to just have a reference to a cake folder in another project again and no luck. It seems, for me, that the cake folder has to be in the current project.

Oh well. Not like that's going to stop me from using Eclipse. It has been an invaluable resource for me!
posted Wed, Aug 15th 2007, 15:46 by Christopher E. Franklin

Question

15 Helpers that use paths e.g. image javascript and css

Thanks for the great tutorial! However I am a bit new to CakePHP and I encountered something odd.

I have installed CakePHP 1.2 and followed the convention you described in the tutorial, I've copied the APP dir, renamed it, changed the APP_DIR constant in /app. Now when I use the css helper in my default layout it links the stylesheet like this:



and not like:



Everything else is working just fine, altho I'd think that the javascript and image helper would do the same.

Did I do something wrong? Is it a Bug?
posted Fri, Aug 17th 2007, 14:42 by Bas

Comment

16 Now the paths

Since they got filtered:

/cake/app/webroot/css/default.css

instead of:

/cake/new_app_dir/webroot/css/default.css

And next time I will use the edit function ;)
posted Fri, Aug 17th 2007, 14:45 by Bas

Bug

17 Excellent Tutorial

But I'd like to add the mere one step that I noticed missing:

Uncomment line 118 in file C:\xampp\apache\conf\httpd.conf

i.e.

#LoadModule rewrite_module modules/mod_rewrite.so

becomes

LoadModule rewrite_module modules/mod_rewrite.so

posted Fri, Aug 17th 2007, 20:45 by John

Comment

18 Eclipse and autocompetition for models

Autocompetition works with NO PROBLEM for Models, guys, this is really simple :)
Only thing you have to do is use a phpDoc:
<code>
class CommentsController extends AppController {

var $name = 'Comments';
/**
* @var Comment
*/
var $Comment;
...
</code>
Actually that probably wont work in Aptana's PHP editor, because its in early stages of developement and lacks context (scope) on autocompetition.
Above example is for PDT, which is (actually) best choice for PHP developement on Eclipse.
posted Sat, Aug 18th 2007, 21:01 by Tobiasz Cudnik

Comment

19 docblocks make it worth a million


Autocompletion is one thing that helps a LOT. but...

Even better is the API: Hovering your cursor over any CakePHP method shows the documentation. No longer need to glimpse over to another window just to remember the order of parameters to those effective Cake calls.

And don't forget to document your own works with docblocks. You'll be glad when implementing a new feature six months later!

posted Wed, Aug 22nd 2007, 02:34 by Antti Pikkarainen

Question

20 org.apache.xerces not in Eclipse 3.3

I was wondering if there is a way to install the wst plugins required by the php plugins withought manually installing org.apache.xerces.

I am wondering if org.apache.xerces was removed from 3.3 for a reason.

Cheers
posted Mon, Aug 27th 2007, 22:59 by Ahmed Kamel

Comment

21 Using Ant to Upload

Francis,
Thank you so much for posting your build.xml file! I've been using ant for many things, but I had no idea you could use it for FTP. I like your script, but as I am solely interested in just posting it to a server, I took it and modified it.

http://zviband.com/2007/09/11/uploading-cakephp-code-via-ant/
posted Wed, Sep 12th 2007, 07:29 by Zvi Band

Comment

22 Ant the powerful

Zvi,

Glad you find it useful, it can do a lot of stuff.
If you notice I also have a target to encrypt the source before uploading. It still has lots of issue and most of it is about the limitation of FTP, webdav is more powerful but havent' tried using it bec it's not installed in my server.

Francis aka nukem
posted Wed, Sep 12th 2007, 10:50 by Francis

Question

23 code completion

Many thanks to Tobiasz Cudnik for his comment, which makes code completion work in Controllers. My question is, is it possible to make code completion work in a View? e.g in myview.ctp, get code completion on $html->

Also, why set up a project for cakePHP core code? You can add the cake code to the project's Include Path.
posted Sun, Oct 7th 2007, 10:05 by Stuart Grasse

Comment

24 How I Got Code Completion Working

Autocompletion works with NO PROBLEM for Models, guys, this is really simple :)
Only thing you have to do is use a phpDoc:
...
Above example is for PDT, which is (actually) best choice for PHP development on Eclipse.


I could not get code completion to work in PDT but, I did get it in PHPEclipse.

I was having a problem of getting code completion before but, figured out what was going wrong.

For me, when I switched views to the SVN Repository Exploring perspective and wanted to check out my code, I did not notice that there were in fact, two options. I chose the default first option of just checking the code out.

To get the code completion to work for me, I had to choose the second option of "Find/Check Out As..". This gave me a new dialog box which has several options. The first radio button, "Check out as project configured using New Project wizard" is what I chose. The next window asks what type of project. I selected the PHP / New PHP Project option. Be sure, that if you have both PDT and PHPEclipse installed, to note what the icon looks like. PHPEclipse is the blue oval that says "PHP" in it and the PDT is a folder with the letter "P" on it. Go ahead and choose the PHPEclipse one.

Once the project has been made, you should be able to mouse over anything and the PHPDoc comments for that item will show up.

For example:
If I mouse over AppController in one of my controllers:

Controller Class:

<?php 
class MyController extends AppController
?>

I will get a little tool tip that displays what the PHPDocs say over that class.

Another cool feature is that, say you have a model, and you make a call to said model in the controller like so:

$this->Model->findById(1);

You can hold down the CTRL key and mouse over Model and it turns into a link. If you click the link you may get another window asking which file you want to open. If that window does not appear, it means there is only 1 class defined in the entire project of 'Model'. Eclipse will then open the file containing that class for you.

I hope this helps someone because, I have been fighting to figure out what was going wrong for a while now.
posted Wed, Nov 7th 2007, 18:15 by Christopher E. Franklin

Comment

25 Solving Problems on Windows and Linux

I recently ran into a problem. I have been developing a website in CakePHP for about a year now using Eclipse. The test bed and development OS has been Linux all this time but, we recently found out that the site is going up on IIS.

Upon copying the website over to the IIS server, nothing was working at all! Cake couldn't load any components, helpers, models, etc!

After beating my head against the wall for about a week, I checked out Eclipse. I right clicked on the project and clicked Properties. I changed the default encoding from cp1252 to ASCII and the line breaks to Windows.

Wow! It worked.

If you ever have a problem like this and are using Eclipse, check that first.
posted Tue, Nov 20th 2007, 15:08 by Christopher E. Franklin

Comment

26 Setting up Bake in Eclipse when using a central cake core folder

Hi All,

I am using a central cake folder for all of my projects in my dev environment and found the instructions above did not work for me. I ended up doing a bit of adjusting to the paths and now have it working with the following setting:

[using OS X with a macports install of php5 and apache2]

Location: /opt/local/bin/php
Working Directory: /opt/local/apache2/htdocs/cake/console/
Arguements: cake.php bake -app ${project_loc} -core /opt/local/apache2/htdocs/cake

/opt/local/apache2/htdocs is also where all of my projects are, like

app
app2
app3

etc...

Just make sure you have the project selected before you run the bake tool.

cheers, dr.swank
posted Tue, Jan 8th 2008, 06:34 by Julian Phillip Sander

Comment

27 code hinting

I also figured an easy way to get code hinting working with my central cake core folder. Add a project to your workspace that points to the cake folder in your webroot and then include that project in the includes setting of your projects.

works like a charm.
posted Tue, Jan 8th 2008, 06:45 by Julian Phillip Sander

Comment

28 app in url

Regarding the copying of the app folder. In what index.php do I edit the app_dir? I'm assuming you edit the original in the app folder as opposed to the copy in a new folder. After I took this step cake started making urls like: /app/controller/view

I'm using 1.2. What's going on there?
posted Tue, Jan 8th 2008, 17:24 by jd

Comment

29 Code Completion in the Views

I saw this posted somewhere else, can't remember where. Just thought I would add it here as well. Anyways when using PDT you can get code completion in your views by having a small file in the root of your cake projects. I called mine eclipse_helper.php


<?php
exit();
//Add in some helpers so the code assist works much better.
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();
}

?>


Its a bit of hack but it is so nice having code completion in your view files. And it is safe if it ends up on a server somewhere.
posted Tue, Jan 8th 2008, 20:24 by Mark Story

Comment

30 app in url

@jd: what i have is my localhost set up to point my dev domains to the webroot folder of my different apps. I do not change any of the index.php files. If you don't want to do this you can also reach a parralel app using the app folders name in the url like this

http://localhost/app2

this would point you to the webroot folder of the app2 folder in your localhost.
posted Wed, Jan 9th 2008, 07:30 by Julian Phillip Sander

Comment

31 cakephp and eclipse

I used case1.2 and I got this

'php' is not recognized as an internal or external command,
operable program or batch file.


Any help pleae
posted Fri, Jan 11th 2008, 08:31 by Habes

Comment

32 CakePHP and Aptana Studio flavor of Eclipse

I used case1.2 and I got this
'php' is not recognized as an internal or external command,
operable program or batch file.


I got this too, setting up CakePHP with the Eclipse flavor of Aptana Studio Community Edition, after attempting to add "bake" as an external tool.

Has anyone tried this?
posted Fri, Feb 8th 2008, 15:46 by JFinger

Comment

33 Answer CakePHP and Aptana Studio flavor of Eclipse

I used case1.2 and I got this
'php' is not recognized as an internal or external command,
operable program or batch file.


How embarrassing...I just needed to fully follow the instructions as stated above:
Follow the instructions for setting up the CakePHP console on Windows here: http://cakephp.org/screencasts/view/6

Bottom line was to add both of these paths to my environment path in Windows:
"C:\Development\xampp\htdocs\cake\cake\console"
"C:\Development\xampp\php"

Worked like a charm - I am all set now with CakePHP running inside Aptana Studio Community Edition (Eclipse).

posted Fri, Feb 8th 2008, 16:53 by JFinger

Comment

34 Problem with Eclipse 3.3

At the point of linking your project to the Cake core:

Then link the Cake core application this to our application:

1. In the PHP explorer window, right click on the application and choose Configure Include Path.
2. From the projects tab, select Add
3. Then tick the Cake checkbox. (make sure you haven’t closed the Cake project otherwise it won’t be available to check).

I get to Step 2 but there is no Projects tab. They have a project references, but it does not seem to do anything. Can someone help me out, and give some more information on how to accomplish this. Thanks
posted Tue, Feb 12th 2008, 17:02 by Johnathan Pulos

Comment

35 Same here

I'm also having this problem with 3.3.1.1. Is the "Include Path" a feature of Eclipse or of PDT/PHPEclipse? If it's an Eclipse feature, does anybody know where to find it in 3.3.x?

Thanks,
Huey

At the point of linking your project to the Cake core:

Then link the Cake core application this to our application:

1. In the PHP explorer window, right click on the application and choose Configure Include Path.
2. From the projects tab, select Add
3. Then tick the Cake checkbox. (make sure you haven’t closed the Cake project otherwise it won’t be available to check).

I get to Step 2 but there is no Projects tab. They have a project references, but it does not seem to do anything. Can someone help me out, and give some more information on how to accomplish this. Thanks
posted Fri, Feb 15th 2008, 07:37 by Jeff Huelsbeck

Comment

36 Still not working

I have made some progess, but the controller still does not inherit the core classes. Here is how far I have gotten:
1. I installed Eclipse PDT
2. I noticed that I was on the PHP navigator and not the PHP explorer initially, so I opened the explorer by going to Windows -> Show View -> Other -> PHP Explorer (Under PHP tools).
3. I had to convert the project to a PDT project in order to get the "Include Path" ability. Right click the project, and click "Convert to PDT project". Now if you right click you will see the "Include Path"options.
After including the path to the cake core, it stills seems like it is not working. I look in the Outline, and the core classes are not present, and auto complete does not work. Can someone please help us out. Thanks.


I'm also having this problem with 3.3.1.1. Is the "Include Path" a feature of Eclipse or of PDT/PHPEclipse? If it's an Eclipse feature, does anybody know where to find it in 3.3.x?

Thanks,
Huey

At the point of linking your project to the Cake core:

Then link the Cake core application this to our application:

1. In the PHP explorer window, right click on the application and choose Configure Include Path.
2. From the projects tab, select Add
3. Then tick the Cake checkbox. (make sure you haven’t closed the Cake project otherwise it won’t be available to check).

I get to Step 2 but there is no Projects tab. They have a project references, but it does not seem to do anything. Can someone help me out, and give some more information on how to accomplish this. Thanks
posted Fri, Feb 15th 2008, 14:07 by Johnathan Pulos

Comment

37 Include Path for Eclipse 3.3 and the Program option missing...

The way I included the path to the "cake" project in Eclipse 3.3 was to reference it.
So you have your projects like this:
cake
app
cake
docs
etc...

In Eclipse I have two projects, like this:

cake (this is the inner cake dir)
app

I right click on app dir in Eclipse and find a submenu option "Configure Include Path", yet nothing shows up, right? That's what happened to me.
So don't do that, right click on the app dir and go directly to Properties. Then find <strong>Project References</strong>. You'll see your project cake, check it, and you are rarin' to go. Done.

<strong>Program option missing</strong>
For this one, yeah it was weird, all we want to do is link the Cake core to Eclipse, whatsup? Whatsup is that the default settings for Eclipse filter "Program" out so you can't see it unless you uncheck the filters.

I know, that was probably hard to follow, so here it is in black and white:

Do what they say above and get to the dialog box:
<quote>3) Back in Eclipse, from the menu choose Run > External Tools > Open External Tools Dialogue...
4) In the left hand side pane, choose Program and then click on the 'New Launch Configuration' button</quote>

Click on the only option that works above that's called "Filter launch configurations..."
By default, 4 out of 5 options are checked. Uncheck them all. NOW you'll see "Program" and can continue the instructions.

Good to go for now! Good luck.
posted Mon, Mar 31st 2008, 16:43 by JFinger

Login to Submit a Comment