CakePHP和MVC [关闭]

So I just installed CakePHP and I'm VERY excited to work with it.

However, the MVC model is BLOWING MY MIND. I looked at the docs and am very impressed, but completely baffled at what to do.

The tutorials and docs show creation of applications that reflect database interaction and etc, but all I want to do right now is create a simple index page. I've already coded it (html, some style sheets, and basic javascript), but I would like to convert it to fit with the CakePHP model.

Does anyone know of good tutorials to begin the process of translating pages to fit the CakePHP model? Also, I would like to start translating my mindset into the MVC model.

Sure. Here's how to roll your simple index page live without messing around with models, tables, etc:

  1. Create a view -> /app/views/pages/index.ctp and plop in your markup, etc.
  2. Place your stylesheet in app/webroot/css/whateveryouwanttocallit.css.
  3. Pull up app/views/layouts/default.ctp and look for a line in the head that starts with Html->css(...); ?> - change it to echo $this->Html >css(array('whateveryouwanttocallit')); - note, no filetype .css on that, just the name. (Also, you can keep the default stylesheet if you want, just add stylesheets to the array to load them in the layout.)
  4. Browse to localhost/index and you should see your static page.

Cake rolls with a single default controller already in place - the PagesController. It does not use a model (the $uses = false; property.) You can use to that property to disable models if you just want a controller, no database / model functionality. The pages controller and the Cake router are set up to route any request to cake's webroot/:action through the Pages controller without needing to specify /pages/:action. Meaning, localhost/index will route sneakily through pages. (So will localhost/pages/index, but I digress.)

That should get you pointed in the right direction. HTH :)

This MVC tutorial could help you get a better understanding of things.

This might also aid in understanding CakePHP MVC models Hope it helps

The link below is going to help you to develop simple CakePHP method:

http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html

After developing a Blog/Post module from above url you can run your application with http://[site_url]/posts/index

By passing the routing principles in routes.php

Router::connect('/', array('controller' => 'posts', 'action' => 'index')); 

As shown in tutorial you can run your index method as base index page of your site or you can say a home page of your site.

I believe this tutorial will help a lot the beginners.