ActiveState Community

Cake PHP

Posted by jeffg on 2008-09-18 22:19 | Staff Pick!
0.5
JeffG
Fri, 2009-02-20 16:27
  • : 4.1 - 5.*
  • : 4.1 - 5.*

This extension adds code intelligence support for View scripts when using CakePHP. This initial version doesn't do much, except implement some extra magic to import the standard cake helpers into view files, either *.ctp for CakePHP 1.2 or *.thtml for CakePHP 1.1. The extension should offer the correct set of helpers depending on which version of Cake you are using.

Please try this out with your Cake projects and let me know what you think; I don't have a lot of experience with Cake and am *sure* I'm missing something. As well, it is totally possible to integrate cake's console through Komodo's Project Template features. I'd be interested to hear people's opinions about what an ideal workflow would be for this.

Update to 0.2: at HeathNail's suggestion, I allowed the magic to happen for any ctp file in a views folder.

Update 0.3: added support for .thtml files in Cake 1.1, and added additional helpers for Cake 1.2.

Update 0.4: based on additional suggestions from Heath, I've added some additional code intelligence support for CakePHP:

  1. The related model is now added as a property to the controller class.
  2. There is now limited support for model associations. By limited, I mean
    that Komodo will be able to derive the associated model for the $hasOne and
    $belongsTo cases if you use the 'simple syntax eg:

          <?php
          class Foo {
            var $hasOne = 'Bar';
          }
          ?>
        

    I have not yet tackled the more complicated array syntax for defining associations, nor have I done a lot of testing, so post back if you run into problems, or email me directly at jeffg (at) activestate (dot) com.

Update 0.5: hasMany associations should now be correctly handled as well.

Cake Autocomplete

adam | Fri, 2008-09-19 01:17

This is possible to do without the extension but what about the $this-> in views?
Check below:
http://community.activestate.com/forum-topic/komodo-and-cakephp

jeffg | Fri, 2008-09-19 14:07

That's actually the main improvement so far over the previously discussed method. $this is now seen by Komodo as an instance of Cake's 'View' class.

--
JeffG
http://www.openkomodo.com/blogs/jeffg

sitedyno | Fri, 2008-09-19 16:30

The search looks for app/views/ but not everyone will have this folder structure. Actually the more cake projects you do the less likely you are to use the app folder. It would probably work better to have only views/ as a search parameter. I'm referring to line 70 of codeintel_cakephp.py

if filepath.endswith(".ctp") and filepath.find("/app/views/") > 0:

Thanks for putting this together :) I will be using it :)

jeffg | Fri, 2008-09-19 17:31

..and exactly the kind of feedback I was looking for, being a bit of a Cake newb. I've updated the extension, let me know if you run into any issues.

--
JeffG
http://www.openkomodo.com/blogs/jeffg

adam | Mon, 2008-09-22 04:17

It works great with local installation of cakephp but what about working on remote server.
Adding local cake path to Prefs/Langs/PHP works only for controllers and models.
Adding also .thtml extension for older version of cake would be also great :)

adam | Mon, 2008-09-22 05:43

Why not to change to this:
if filepath.endswith(".ctp") or filepath.endswith(".thtml"):
Will work also on remote files and with all versions of cake. Will work on every directory structures.
Additional thing that should be done is to separate old (deprecated) cake code form new (.ctp from .thtml). If autocomplete could be assigned for proper versions (means 1.1 functions to .thtml and 1.2 to .ctp) that would be almost perfect ;-)

canuckistani | Mon, 2008-09-22 13:14

I had wondered about older versions of Cake, but decided to go ahead with the 1.2 because it is what the Cake site pushes. It should be possible to do this by processing the codeintel buffer differently depending on the file extension. I'll try to take a look at this tonight or tomorrow.

adam | Tue, 2008-09-23 04:21

There are many websites using cake 1.1 and needs modifications all the time.

jeffg | Tue, 2008-09-23 09:12

I just updated the extension to 0.3 with support for .thtml files and what I believe is a better set of helpers present for CakePHP 1.2. Try to check it out and let me know if you have any problems or suggestions. =)

--
JeffG
http://www.openkomodo.com/blogs/jeffg

adam | Tue, 2008-12-30 03:50

What about custom helpers? Is this extension work with it?

tokuiti | Sat, 2009-08-08 07:23

Please use inflector to pluralize or sigularize nouns.

- Python Inflector
http://www.bermi.org/inflector/download

eksi | Sun, 2009-09-27 02:15

Do you think about write post about CodeIgniter framework ?

(from eksi ..)