What's the best way to learn mvc in PHP? [clos

2019-02-11 13:23发布

I'm totally new to mvc,how to pick it up?

5条回答
Explosion°爆炸
2楼-- · 2019-02-11 13:48

Maintain some project written in spaghetti code (CSS + JS + HTML + PHP + SQL, all in one single file), then think how you would separate all these and you'll discover MVC.

Kidding aside. Read about it what you can, try some framework but don't avoid maintenance projects. It is in these projects that you'll see the benefits of MVC or at least those of separation of concerns.

See also this related question.

查看更多
迷人小祖宗
3楼-- · 2019-02-11 13:57

Go this way:

  1. Read about MVC (Google it, see the wikipedia article)
  2. Choose a Framework (I suggest CodeIgniter - Has a great user guide)
  3. Then go through the user guide and try the things.

The video tutorials are also good, check nettuts.com for CI.

查看更多
冷血范
4楼-- · 2019-02-11 14:10

You can read all about MVC with a simple google search. However, you won't fully understand the beauty of it until you pick a framework and dive in. I hear great things of CodeIgniter. It was my first framework when getting into MVC.

In the end I chose CakePHP. Why? CodeIgniter, while very simple to get started with, gave me too much freedom for a beginner to MVC. I wanted strict rules and conventions to show me how its supposed to be done rather than what I think MVC should be. Maybe later on down the road I'll come back to CI. Either way you choose, my suggestion is to take a small project you coded, and code it in any of the PHP frameworks out there.

CakePHP's and CodeIgniter's communities are among the most helpful. Join a google group for Cake/CI. Read about what people are trying to do. See what problems people are having and good luck!

查看更多
Explosion°爆炸
5楼-- · 2019-02-11 14:11

Go this way:

  • Know what is MVC
  • Why it is useful
  • How does it work
  • Where it should be used optimally
  • How do frameworks use it (if possible to know)
  • Learn how frameworks implement it (try using a framework)
  • Learn a framework so that you can become habituated to using MVC

I know I might sound foolish, but this way can be of great help to newcomers.

查看更多
在下西门庆
6楼-- · 2019-02-11 14:11

First research the MVC pattern and look for tutorials that explain how to implement it. Next, get an MVC framework for PHP and use that since there's no sense trying to reinvent the wheel and roll your own.

查看更多
登录 后发表回答