The CakePHP Framework: Your First Bite

@dg_den_golotyuk
this is a nice overview of extending CakePHP
http://devzone.zend.com/node/view/id/593
This is an example of using Zend Components with CakePHP.

The same principle can be used with any third party library. For example, in http://cakephp.org/pastes we use the nice Geshi code highlighting library

@mutant
http://cakephp.org/search
will search several blogs about cakephp, the google group and the manual all at once.

@those who want to suggest building their own instead
The advantages of Open Source should be pretty clear by now. The CakePHP community is filled some very good programmers who are willing to contribute ideas, bug reports, code and help. When you need to bring in new developers to help you with a project you can have them read the manual, api, and review the many resources available. Otherwise, you have to sit there explaining how your homegrown framework works.

CakeForge has many sample applications. For instance, the code used for http://rd11.com, a blog and photo gallery site is freely available at http://cakeforge.org/projects/rdos You will also find CakeMap, which use a google maps helper and makes adding maps to a CakePHP based site easy. And the code for CakeBin is available there and gives the nice example of using Geshi within CakePHP.

It think this comment could go both ways, you say it is not capable of creating complex applications, yet there is no example given of a complex application you would like to create and found cake not suitable for it. I already posted a link above to a description of an application we created for a client through the Cake Software Foundation. If you browse the CakeForge site you will see there is a simple shopping car called bakesale, also a few CMS projects and many more are listed.

http://cakeforge.org/top/mostactive.php

As a matter of fact, I think I’m going to take a page out of my own book. I’m going to try to make a simple shopping site. I’ll document my trials as best I can, and report back here. Mabey that will help people understand the barriers to entry in regards to Cake.

This sounds like a great idea, stop by the IRC channel if you need help, someone is always online to help by answering your questions. You will find me there often too.

Java web based client:
http://irc.cakephp.org/

If you have your own IRC client
irc.freenode.net
#cakephp

I’m so done with the “blog in 20 minutes” thing. Why would anyone write thier own blog when there are tons out there that are top-notch? Lets see a sample application that has real-world use. A CMS, a simple shopping cart, show complexity by demonstrating the ease of development when developing something ususual in a shopping cart site. I think the thing that eveyone gets hung up on is that its like learning a whole new language no matter how well you know PHP, Cake is difficult when you don’t know it front/back/sideways, leftwise and right, especially when you are trying to figure out how best to proceed in implementing business logic.

Perhaps that’s what people mean – CakePHP isn’t suited to complex apps, not because it’s not suited, but because they’re not suited to having to learn this potentially complex system of doing things. I don’t think there is any need to beat people up for not seeing how Cake can build complex sites – if you support Cake, show some examples, otherwise, you’re just a troll.

As a matter of fact, I think I’m going to take a page out of my own book. I’m going to try to make a simple shopping site. I’ll document my trials as best I can, and report back here. Mabey that will help people understand the barriers to entry in regards to Cake.

Particulary if you want to download the latest manuals and software go to : http://cakeforge.org/top/mostactive.php
but the manual has some errors for examlpe in the hasAndBelongsToMany assosiations. I will write a good tutorial about assosiations because is one of the most important things to grasp to understand cakephp. I think after seeing this article here in sitepoint that cakephp migth be the best choice not only because there is an article here but because it has the most active comunity.

Sorry. Couldn’t reproduce the first simple exsample. How should the memo screen (http://www.cakephp.dev/notes/) appear after only creating two files (note.php and notes_controller.php) and a databse table? I see only the 404 apache message.

Nice article!
the cake is drawing more and more interest :slight_smile:
I found to work well with simple models!
Also Jonathan Snook is starting a new blog about CakePHP: http://withcake.com/

I’ve read up on cake a little more now. And as most other frameworks I’ve tried, it fails when it comes to caching. It might just be me, but I need caching to work, and I need it to work the right way.

from the cake manual:

First, you should be aware that Cake will automatically clear the cache if a database change has been made. For example, if one of your views uses information from your Post model, and there has been an INSERT, UPDATE, or DELETE made to a Post, Cake will clear the cache for that view.
This is fine if you run an article site, or a blog. But as soon as you start doing something a bit more complex it gets unusable. IE you have a download site with downloads listed. Of course you keep track of the downloads and present this to the users. the more downloads you have, the longer time it takes for php/mysql (I’m usually using mysql) to process this. You might not notice this at the beginning, as the site is small. But as soon as you start getting more users, it will be a drag. Caching the list and make it update every hour will save you A LOT of processing power. The more users the more processing power you save. I run a site which have a usual load of 80-120 users. When these users hammer a download list, caching saves my dedicated server from going down. I had huge issues with load until I implented caching at some parts of the site. It saved me from investing into another dedicated server and set up loadbalancing

Caching is a big moneysaver, and I see it as the most important backend part of a site (next to session handling). If I can save $400 a month on servers because of cache, I will use it. And I will use it on every project, no matter how small. Never know if a small project grows big. If a frameworks caching can’t be used, the framework can’t be used. I’d rather use a framework without caching and build my own caching library. And I won’t use a framework that implements an unusable caching engine. It bloats the engine code and it makes me wonder about the rest of the code.

The nice thing about the current caching is you use it only when you want, you have to turn it on, so using your own caching system is very easy. There is also specifc code you can use to not cache a specific part of your page.

simple example:

http://cakephp.org/pastes/show/6f197fba0d40ec4c2641781ac5078557

The example you used above would be very easy to implement and cache a specific part of the page being displayed while keeping another section dynamic.

Another suggestion, if you see something you have a question about, stop by our freenode.net irc channel #cakephp I am there often, or visit the google group http://groups.google.com/group/cake-php.

A feature request or bug report is handled on the trac site https://trac.cakephp.org/

Why would I use 2 caching engines in one aplication? I’d rather have one that can do what I want it to do. And to be honest, I prefer a framework with a minimal of functions and a library at the side were you pick the functions you want. This will lower cpu and memory usage a lot and help maintain fast and slick aplications. I find a lot of the frameworks are built to speed up the work at the loss of quality. To me, speed and security comes first. The frameworks I’ve tried up to now have not been able to deliver that.

I think you misunderstood me, there is nothing forcing you to use the included caching, and you must turn it on to use it, I said nothing about using 2 caching engines, re-read my post. The core caching is not even loaded unless you need it. Same with the rest of the core framework code only what is needed is loaded.

And to be honest, I prefer a framework with a minimal of functions and a library at the side were you pick the functions you want.

To me a framework is not only libraries but a set of conventions that make it easier to build your application, by sticking with these conventions you will see application development is much easier and faster. There is nothing forcing you to use these conventions, but by not using them it will make development harder trying to use a framework built as Cake is, not only that, you will write more code trying not to use these conventions, which defeats the purpose of using a framework in the first place IMO.

Cake adds structure to an unstructured language, and those who use it could not agree more that this structure has been a blessing for them in their daily development activities.

What you describe as wanting in a framework is nothing more then PHP itself…

I should have done this to begin with, showed you an example…


<?php
class Download extends Appmodel{
	var $name = 'Download';
	
	function _clearCache($type = null){
		//since we are overriding the Model::_clearCache() cache will remain 
		//until the time set to delete cache is reached
	}
}
?>

And all is well in your application…

Thanks for introducing me to CodeIgniter. It’s exactly what I needed.

Is anyone going to offer a solution to this problem? Two people so far have had it. Make me 3. Probably loads more…

ok, after a quick play I think I can answer my own question

in your apache config file uncomment the following (approx line no in brackets)

(192) LoadModule rewrite_module modules/mod_rewrite.so
(237) AddModule mod_rewrite.c

mine now seems to work

BUT I’m no apache expert so perhaps someone more knowledgable can confirm this is the correct/safe thing to do.

T

Yep I was going to suggest that it may be happening because your Apache install does not have mod_rewrite installed, but you beat me to it. Cake needs that module to work correctly.

Not sure what version of Apache you are running, but I don’t think this is necessary, just the LoadModule call.

If you remove the comment from the BASE_URL define in app/config/core.php you can use CakePHP without mod rewrite.

URLS would be www.example.com/index.php/notes in this article example then

Most of this is covered in the manual. http://manual.cakephp.org/

This doesn’t work with Windows/Apache2.2, where even the php4apache2.dll downloaded from php.net doesn’t work (it’s said this file is for Apache2.0, you can download a 2.2 replacement from http://www.apachelounge.com/download/).

The example view shows up only on http://localhost/index.php?url=notes. So it seems the mod_rewrite isn’t working.

Bump for truth.

  1. Create two class files
  2. ???
  3. Profit!

I’m using IIS. Is there something I’m missing or does the article assume I’ve taken other steps?

Edit: The article mentions that IIS is supported by cake, but the solutions so far involve Apache and mod_rewrite. Is this article dependant on mod_rewrite?

  1. Please check http://ask-leo.com/does_iis_support_url_rewriting.html for more details.

  2. This tutorial depends on mod_rewrite if you want it work just as taught to show something with only two files added. A way around mod_rewrite is try this link
    http://localhost/index.php?url=notes. And then when you add more views, e.g. add, edit, you manully change the link by inserting “index.php?url=”.

  3. The answer to the post above is

The example view shows up only on http://localhost/index.php?url=notes. So it seems the mod_rewrite isn’t working.

when changing httpd.conf, besides
LoadModule rewrite_module libexec/httpd/mod_rewrite.so
AddModule mod_rewrite.c (not needed for Apache 2.2)

Make sure the AllowOverride is set to All for the correct Directory.

Another answer concerns anoobis’s question:
http://wiki.cakephp.org/tutorials:cake_under_iis_without_rewrite