MVC - 控制器类教程 [英] MVC - Controller class tutorial

查看:116
本文介绍了MVC - 控制器类教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一本指导我理解Controll函数和编写我自己的控制器+模型的最佳实践的教程/书



提前感谢。 / p>

解决方案

确保已经发布了大量的链接,以帮助您入门,但是创建MVC的一些重要因素是:




  • 静态注册表类(存储对象并获取全局范围)

  • 路由器/方法和来自URI的参数)

  • 基本控制器(只是用户控制器可以扩展的小型抽象类)

  • SPL自动加载将允许用户扩展类如 Model_Database

  • 结构(您应该根据名称创建目录,Ie Library_session 将加载 /library/session.class.php

  • 模型抽象所有类型的存储,数据库,磁盘等)

  • 错误跟踪(始终确保您的日志记录和捕获错误)



它们只是您在创建系统时应该考虑的几个提示和想法。



您还应该做的是用户其他框架和构建一些示例项目,学习如何应用一个MVC框架,所以当你构建一个你知道用户应该期望什么,那么只是真正研究框架的核心结构。



在PHP中考虑以下通常是如何MVC工作




  • 控制器(这取决于URI执行)

  • 模型(从控制器访问,应为数据的I / O)

  • 查看(模板)



    • ,但您可以使用 MVCL M odel / V 语言/ C 语言)



      语言不是原始文档中的特定语言但在模式结构方面已经采用了几次。下面的文件结构示例将指导您了解 + L


      $ b的主要用途$ b

        M:\catalog\model\catalog\product.php 
      V:\catalog\view\template\product\ product.tpl
      C:\catalog\controller\product\product.php
      L:\catalog\language\english\product\product.php

      公司/项目使用此方法的示例是: OpenCart ,我高兴地推荐你在建筑中寻找!


      I am looking for a tutorial / book that guides me to understand the Controll functions and the best practices to write my own controller + Model

      Thanks in advance.

      解决方案

      Im sure theres plenty of links been posted to get you started but some important factors in creating an MVC is:

      • Static Registry Class (Store objects and fetch with a global scope)
      • Router (A class that determains the controller/method and params from URI's)
      • Base Controller (just a small abstract class then the users controller can extend)
      • SPL Auto-loading (this will allow users to extend classes such as Model_Database)
      • Structure (you should create directories in accordance with names, I.e Library_session would load /library/session.class.php)
      • Model Abstraction (Account for all types of storage, Database, Disk etc)
      • Error Tracking (Always make sure your logging and capturing errors)

      They are just a few tips and ideas you should be thinking about when you create your system.

      What you should also do is user other frameworks and build some sample projects, learn how an MVC Framework should be sued, so when your building one you know what the user should expect, then just really study the core structure of the framework.

      Take into consideration in PHP the following are usually how MVC Works

      • Controller (this is executed depending on the URI)
      • Model (Accessed from the controller and should be the I/O of Data)
      • View (Templates basically)

      but you can work with a MVCL which is (M odel/V iew/C ontroller/L language)

      Language is not a specific in the original documentation but its been adopted a few times in regards to the pattern structure, An example of the file structure below will guide you into whats the main purpose of the +L

      M: \catalog\model\catalog\product.php
      V: \catalog\view\template\product\product.tpl
      C: \catalog\controller\product\product.php
      L: \catalog\language\english\product\product.php
      

      An example of what company / project uses this method is: OpenCart, AND I HIGHY RECOMMEND YOU LOOKING AT THE ARCHITECTURE!

      这篇关于MVC - 控制器类教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆