Contact Us

Command line fun in CakePHP 1.2

Posted on 16/10/06 by Felix Geisendörfer

Deprecated post

The authors of this post have marked it as deprecated. This means the information displayed is most likely outdated, inaccurate, boring or a combination of all three.

Policy: We never delete deprecated posts, but they are not listed in our categories or show up in the search anymore.

Comments: You can continue to leave comments on this post, but please consult Google or our search first if you want to get an answer ; ).

If you, like many others, already have dived into the 1.2 branch of CakePHP, you've probably already made some pleasent discoveries as far as upcoming features go. One of those cool new things that'll probably ship with the 1.2 release, is a new bake script, called bake2.php. Like the old one, it can be found in /cake/scripts/ and is called via your command line. But unlike the old bake.php, which was only used to auto-generate code for you, this one follows a much cooler concept. The main idea is to have an interface to a wide variety Tasks. Those Tasks can either be part of the CakePHP core and rest in /cake/scripts/tasks or of your individual application and go into /vendors/tasks. This will help us to automate things we used to do by hand. For example if you are developing an image uploader, you probably want to clear the upload folder and database table from time to time, because it get's filled up with too much crab in the process of development. Or if you are like me, you probably want to write a DeployTask that can be used to automate the upload of your website via SVN diff and FTP ; ).

So if you are curious to try out this new feature, here is how you would create a new Task:

First of all, create a new php file in /vendors/tasks. We'll call ours cake_task.php right now. So after you've created the file, fire up your IDE and enter this code:

class CakeTask extends BakeTask
    function execute($params)
        echo "CakePHP 1.2 will be very tasty!\n\n";
        echo "This Task was called with".count($params)." parameters.\n";

So, as you might have guessed, the $params parameter will contain an array with additional data that can be used by the Task to perform individual actions. In order to call our incredibly productive task, all we have to do is this (after switching to the /cake/scripts directory):

php -q bake2.php cake a b c

After hitting enter we'll be informed that our task was called with 3 parameters. Now even so this wasn't exactly a very useful example, I hope it was good enough for you to grasp the concept and possibilities this new feature offers, and I'm sure we'll see some good Tasks in the Bakery soon ; ).

--Felix Geisendörfer aka the_undefined

PS: I'll need some testers for the alpha version of the DeployTask I'm working on right now soon. So if you are willing to give it a try, let me know in the comments of this post.


You can skip to the end and add a comment.

PiotrB  said on Oct 16, 2006:

I develop medium sized app with CakePHP, and I'd like to test your DeployTask

Felix Geisendörfer said on Oct 16, 2006:

Right on PiotrB, I'll do my best to get this alpha version rolling out ; ).

roliver  said on Oct 17, 2006:

Music to my ears, I'll certainly give your deploy task a whirl

Evan Sagge said on Oct 17, 2006:

Wow. This is great stuff. I just hope they could use the new bake to provide a command-line based testing framework for cake.

Felix Geisendörfer said on Oct 17, 2006:

Evan: Good that you mention that, the Caketaser testsuite that I'm working on will get it's own command line task as well (even so the GUI version is going to be much more comfortable). If things work out nicely you'll even be able to couple it to the deploy task in order to not ship anything that hasn't been tested. Uhm, gonna have to do some work today I guess : ).

Evan Sagge said on Oct 18, 2006:

That would be awesome for CakePHP. I know a lot of people prefer a graphical output, but really, all I need in my testing are just the text. :)

Would this bake script be usable with CakePHP 1.1? Or is it exclusively for 1.2 versions?

Felix Geisendörfer said on Oct 18, 2006:

Evan: The script will be for 1.2. However, if somebody really needs to get it working with an 1.1 install, it wouldn't require lot's of work to do so.

Evan Sagge said on Oct 19, 2006:

That'd really be nice. I'm using Cake 1.1 for a project, and it's been hell deploying my app through ftp. I'd been deliberating whether to study ant for use with my deployment, but abandoned the whole plan after I've read your previous post on it.

Felix Geisendörfer said on Oct 19, 2006:

Yeah, manual FTP deployment is hell, especially if the client one uses (FileZilla for me) doesn't support recursive chmod (which you need for /app/tmp). I hope I'll have something up and running soon.

[...] Felix already wrote about the new bake2.php script. This script is rather simple, it simply executes tasks, i.e. classes with a certain interface. At the moment, there exist two such tasks in the branch of CakePHP 1.2: AppTask and DbconfigTask. Let’s have a look at them, even though they are not finished yet. [...]

Kim Fransman said on Dec 14, 2006:

Hi, i tested it out and it worked lika a charm, just wonderful, As always, good work Felix! All i have to now is to learn SVN a bit better. :-) I have recently rolled out my first app in 1.1 and the thougt of Cake getting better excites me more than porn.

ramin  said on Jan 03, 2007:

In response to this comment from Felix:

"Evan: The script will be for 1.2. However, if somebody really needs to get it working with an 1.1 install, it wouldn’t require lot’s of work to do so."

I'm totally to CakePHP, Felix said that it's possible doing it in 1.1, anybody has any idea how? Any useful directions on this?

Thanks a lot.

[...] Command line fun in CakePHP 1.2 by Felix Geisendörfer [...]

[...] Although I don’t really use it much, there are some times where it just comes it so handy. And with the advent of CakePHP’s Bake feature, it’s become damn near and essential tool. Prior to DreamHost I would have to Bake on my Windows environment, then upload to where I was really hosting. [...]

chris  said on Nov 07, 2007:

Is there any way to use bake via a web interface (in case you dont have access to a console on your development server?)

Irfan  said on Nov 14, 2007:

Is there any way to use bake via a web interface (in case you dont have access to a console on your development server?)

anyhelp on the above question ?

Tallbrick  said on Dec 12, 2007:

I am having trouble locating the scripts directory inside the cake folder. Here is a link to 1.2:

I did find cake.php and bake.php in another area:

It looks like the project has deviated from the 1.2 version this post referred to back on 2006

LiNo said on Jul 13, 2009:

Hello everyone, just like to ask if it is possible to bake an additional model/controller/view for a new database table to an existing project?

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.