tags:

views:

2662

answers:

7

I am trying to learn CakePHP. I'm having trouble understanding the concept of MVC. Does anyone have any advice for me?

+1  A: 

First of all you ought to understand the MVC PATTERN, then try to learn the PHP basics and last learn the cake PHP framework.

But please don't take me wrong. When learning some technology, taking shortcuts and "easy ways" is not always the best thing to do. A good fundamental knowledge well sedimented is strategical to be successfull.

Ricardo Acras
+4  A: 

I had to bring a couple of developers up to speed quickly with CakePHP recently and I bought them a copy of CakePHP Application Development: Step-by-step introduction to rapid web development using the open-source MVC CakePHP framework by Ahsanul Bari. While CakePHP 1.2 has been a bit of a moving target for a while and so a few of the things are already out of date, it's generally an excellent introduction to using CakePHP in anger (moving beyond the typical blog tutorial).

DreamCatch's RTFM comment is interesting. While I'd agree that CakePHP's documentation is pretty useful now, it's patchy in places and until recently was utterly dreadful. It's come on a heap in the last year.

reefnet_alex
+2  A: 

MVC for dummies explained as a banking analogy : http://teknoid.wordpress.com/2009/01/06/another-way-to-think-about-mvc/

Alexander Morland
+2  A: 

Well, cakephp is fairly easy to understand...

Without going really deeply

the controllers contain the action you want to do....everything that is business logic should go there. Every public function in the controller is an action.

When you get use an action, it will redirect to a view in the views folder. This is where you put what will be drawn.

The model contain what you need to set/get/update/delete data on your databases.
The controller use the model and generally put datas in the $data variable. But it could be anything.

controller are named after the model
the model is named after a database table or anything you want
the views are named after actions in your controller

actions are controller functions.

My guess is that if you really want to understand how it works...
Get there and do the blog tutorial >> http://book.cakephp.org/view/219/Blog
Read that >> http://book.cakephp.org/view/10/Understanding-Model-View-Controller

If you have time. read the whole documentation. It's not that long. You shouldn't have problem understanding how to make something with cake after that.
http://book.cakephp.org/

Sybiam
A: 

Having been your position myself I think the reason many PHP programmers find MVC frameworks hard to understand is PHP's way of treating websites as a collection of standalone scripts. Most MVC frameworks treat a website as as single application, which requires changing the way PHP programmers think about web programming.

If you are finding MVC frameworks difficult to understand, try to implement MVC yourself. Your first implementation is most likely to be lot inferior than commonly used MVC frameworks, and it may not be practical to use it in production sites, but after this experience you will:

  • Understand MVC well enough to use any existing MVC framework
  • Know PHP better

While you are implementing your MVC framework, read the docs/basics apps of established MVC frameworks (Zend Framework, CakePHP etc). You'll get many ideas which you could implement in your experimental framework.

The basics to remember:

  • All database access goes to Models
  • Controllers' responsibility is limited to only getting necessary data from Models and passing them to Views
  • Views should contain only presentation logic

Some helpful resources to get started:

MVC (Wikipedia)

Understanding MVC in PHP

Implementing MVC in PHP: The Controller

Imran
A: 

Go through the basic blog tutorial, and then start adding stuff and playing with it - learn by doing.

Also, try to find as many third-party cake apps and learn how they work. Cake is only scary at first because of a lot of new terms and concepts.

Once you comprehend all that basic stuff, cake becomes a powerful and simple tool and you'll probably never stop using it.

dr Hannibal Lecter
A: 

Go on http://cookphp.blogspot.com/2009/09/cakephp-for-beginners.html it is quite easy one

martin