How Do You Convert a Page-Based PHP Application to MVC?

后端 未结 11 751
野趣味
野趣味 2021-02-01 09:48

I\'ve been struggling for some time now with exactly how to recode a page-based PHP application using an MVC framework. Just for background, I am having to move the app into MVC

11条回答
  •  礼貌的吻别
    2021-02-01 10:15

    I went through something like this last year. I converted my mostly static PHP web site pages to use the Kohana PHP Framework. I made each web site section a controller, with views for the individual pages. The main page views included other views for header, and footer. Some of the views, such as for articles, were reusable by different controllers. The result was an MVC site with the same page URLs as the original web site.

    EDIT: The URLs are in the format of /controller/method?arguments. As an example, on my site, the URL for /computer/article.php?id=# uses the article function in the computer controller. The computer controller, in turn, uses an article model to load the data into an article view with nested paragraph views. This also illustrates that even though the prior version of the site had page names with the .php extension in the URL, this can still translate to a controller class method and the same URL works in the MVC based version of the site. This should give you and idea of how Kohana might work for your site.

提交回复
热议问题