RSS
 
03. Oct. 2010

Console for CakePHP

03 Oct

Windows and Cake1.x

Nothing easier than that! 2 minutes and it works.

I prefer WAMP (XAMPP sucks). But I describe it for both. WAMP has the advantage that you can easily switch php versions (5.2.10, 5.3.0, 5.3.1, …). For the path it is annoying to edit the version number all the time. So (WAMP ONLY!) copy your desired php version from /bin/php/php5.x.x to /bin/php/php_for_console. If you now need to switch the php version you can simply replace the files in this folder. You don’t have to edit the system path. For XAMPP there is usually only one php directory, anyway.

We need to add these two paths to the System Path: C:...\xampp\php; (for XAMPP) OR C:...\wamp\bin\php\php_for_console (for WAMP with copied folder) OR C:...\wamp\bin\php\php5.x.x (for WAMP without the above trick – not recommended)

AND C:...\project\cake\console (your project is usually inside www or htdocs folder)

Here you could set up a second cake folder, as well, which only serves the console (e.g. “/C:...\wamp\bin\cake”). This way the cake version for the console can easily be managed – separately from any cakephp app.

We need to open “my pc properties” -> “environment variables”. In “path” we need to append the 2 paths from above.

Separate them with semicolons: ...;C:...\xampp\php;C:...\project\cake\console Done! It should now work right away on any Windows (XP, Vista, 7). Not sure if a restart is necessary, though.

Please note: If you have multiple partitions, don’t put your cake/php stuff (WAMP, XAMPP) on C:. There might be some user rights issues. You are better off using D:/ or any other partition. And you shouldn’t have any persistent data on the system partition, anyway. I usually have windows and installed programs one C:\, everything else is on other partitions.

Don’t just open a console. In order to use the console for any of your apps you need to navigate to the APP folder. Otherwise “cake …” etc will not find the shell scripts in your app: C:...\project\app>

Hot Tip: To quickly open a cake console on any of your apps, simply press SHIFT + right click on the app folder. You will now see a new button “Open console here” / “Eingabeaufforderung hier öffnen”. That’s it. With “cake” you should see the welcome screen and a list of all possible shells.

And – if you did everything right – you should be able to execute your shells like so:

cake command args -params
For example to bake a model:
cake bake model

Linux

See my new article about it

NEW – Cake2.x

For Cake2 we need to adjust the project path like so C:...\project\lib\Cake\Console Nothing fancy after all.

HOT TIP

If you need to run both 1.x and 2.x on the same system, don’t append anything besides the pure PHP path to the System path. You can then create two keyboard shortcuts (like I do) for the different versions with a tool of your choice. I created cw1# (“cake windows v1)” for ..\cake\console\cake cw# for ..\lib\Cake\Console\cake So I am in the app path and just type cw# bake which automatically translates cw# into the above path and then, of course, starts up the bake shell. With the ..\ syntax CLI always uses the correct cake version (in /trunk/lib if your project app is in /trunk/app).

 
No Comments

Posted by Mark in CakePHP

 

Tags: , , ,

Leave a Reply

Tip:
If you need to post a piece of code use {code type=php}...{/code}.
Allowed types are "php", "mysql", "html", "js", "css".

Please do not escape your post (leave all ", <, > and & as they are!). If you have encoded characters and need to reverse ("decode") it, you can do that here!