Cake for beginners
A quick guide for the curious
Note: This guide is not endorsed by or affiliated with the Cake developers. I just wrote it because I recently discovered Cake and had lots of questions. I thought other people might be in the same boat. Please e-mail corrections to graham at grahambird dot co uk
- What is Cake?
- Is Cake for me?
- Is Cake better/worse than Rails?
- What will Cake do for me?
- What do I need to run Cake?
- Can I install Cake myself?
- Will I need to use the command-line?
- What is scaffolding and does Cake do it?
- What about Ajax?
- How do I use CSS, Javascript and other stuff with Cake?
- OK, I want Cake!
- Where can I get more info about Cake?
What is Cake?
Cake is a framework for PHP in the same way that Rails is for Ruby. Essentially, it's a tool designed to help PHP developers avoid reinventing the wheel all the time.
Is Cake for me?
Cake is for you if:
- you like the cleverness and automation of Ruby on Rails
- you already know PHP and don't have time to learn another language
- you are tired of creating bespoke code to do very similar things
- you use shared hosting
- you want to get more done in less time
- you want to use templating
- you want nice, searchable URLs - not things like post.php?id=12345678
- you don't want to run things from the command-line
- you only have one MySQL database (table prefixing is an option)
Is Cake better/worse than Rails?
Cake follows the same MVC model that other frameworks typically use, and I think it's fair to say that the developers were initially inspired by Rails. However, because Ruby is different to PHP, I don't think the two frameworks can be directly compared.
The way I look at it, Rails is a great idea, but to use it you need to learn a new language and have specialised hosting.
On the other hand, with Cake you can stay in familiar territory (PHP) and use pretty much any host while enjoying the benefits of a frameworked approach.
What will Cake do for me?
Some of the things Cake does so you don’t have to:
- eases creation of standard content management functionality (adding, editing and deleting)
- uses template-like Layouts and Views to separate logic from presentation
- validates form fields
- automatically escapes data saved to the database (to prevent SQL injection attacks)
- includes callbacks (eg do an action before or after save)
- allows for both test and production databases
What do I need to run Cake?
Any hosting package with Apache, PHP 4.3.2 or higher and MySQL. If mod_rewrite is enabled it will allow you to use nice, search-friendly URLS. Cake does run on IIS too.
Can I install Cake myself?
Yes, as long as you can FTP to your webspace. You can get Cake running without any configuration changes from your host.
Will I need to run things from the command-line?
No.
What is scaffolding and does Cake do it?
Essentially, scaffolding means running a script over your database structure to automatically create some basic content management functionality (ie web forms). And yes, Cake does do scaffolding. See my scaffolding tutorial for more info.
What about Ajax?
Yes, Cake includes Ajax functions too. My Ajax task list tutorial is an introduction to Cake with Ajax.
How do I use CSS, Javascript and other stuff with Cake?
You can store all your non-Cake files (css, javascript, images, etc) in a separate folder.
OK, I want Cake!
Download the most recent version from CakeForge.
Where can I get more info about Cake?
You can visit the official website, read the Wiki or post to the Google Group.