您的位置:首页 > 运维架构 > 网站架构

OpenCart开发指南翻译 MVC-L架构简介 Introduction to MVC-L

2014-11-03 09:42 561 查看

个人翻译水平有限,难免有翻译不到位的地方,望指正。

入门Getting started

对于想要了解php一般网络架构的开发者来说,OpenCart是一个非常棒的平台,他是最简单的符合MVC架构的应用之一。OpenCart使得你可以通过它那熟悉的PHP、MySQL和HTML技术学习MVC架构。本指南只需要你对HTML、CSS、JavaScript、PHP(包括类和继承),和MySQL有基本的了解,将描述它们是如何在OpenCart系统中使用的。

OpenCart is an excellent platform for developers looking to understand PHP web frameworks in general. It is one of the easiest to follow MVC structured applications available. OpenCart allows you to learn the MVC framework while giving you access to the familiar
PHP, mySQL and HTML technologies on which it is built. This guide will assume a basic understanding of HTML, CSS, Javascript, PHP (including classes and inheritance), and mySQL, and will describe how these are used in the OpenCart system.

MVC(L)

OpenCart遵从MVC设计模式,其组件((Model View Controller)可以分解如下:

M-模型 

直接和数据库打交道,取出数据并整理结构以适于前端呈现。模型通常涉及数据库查询和一点其他的东西。如果你写过mysql的查询语句,那一定很容易适应OpenCart提供的同样的数据访问方式。OpenCart并没有使用ORM(见注解),但是允许你编写直接的数据库访问。

V-视图

这是MVC模式的显示部分,M和C尽可能多地将逻辑从视图中分离出来,这意味模板更简单了。因此,为了重新设计你的整个网上商店界面,你只需修改View组件,而M,C和L将保持不变。在OpenCart视图文件的后缀是.tpl。 

C-控制器

控制器把来自模型的数据、所有安装时或者模块保存的配置选项汇总起来,然后选择一或多个合适的视图文件呈现它。

L-语言

OpenCart将MVC扩展为MVCL,提供一种展现不同语言的简单方式,以用于国际化。你可以使用语言文件存储任意的文本比如头部,标题,按钮文本等等,因此你仅仅需要为每一个语言提供一个文件即可实现网上商店的翻译。

OpenCart is designed to follow an MVC design pattern. The components of MVC (Model View Controller) can be broken down as follows.
M - Model This is where you will interact directly with your database, pulling data out and restructuring it to a format that is suitable for your frontend. This will usually mainly consist of DB queries, and little more.
If you are used to writing mySQL queries, you will enjoy the way OpenCart provides access to continue to do just that. OpenCart does not use an ORM, but allows you to write direct database queries.
V - View This is the display side of the MVC pattern. The idea of the M and C is to pull as much logic out of the view as possible, meaning simpler templates. In order to redesign your whole store, you simply modify the View
component, the M, C and L would remain the same. The view files in OpenCart have the .tpl suffix.
C - Controller This is where you will pull together the data from the Model, any config settings saved with your install or modules, and then render it by choosing the appropriate View file(s).
L - Language OpenCart extends MVC to MVCL, providing an easy way of separating language specific information for internationalization. You can use language files to store any text like headings, titles, button text, etc.,
so that you only need to adjust one file per language to provide translations of your store.

目录结构Directory structure

OpenCart目录结构大概基于两个OpenCart应用程序的重要组成部分。前台和后台管理界面分别对应于在OpenCart顶层安装目录下的两个文件夹。前台文件夹称为 catalog/ 和后台管理文件夹名为admin/。如果你只需要对前端做修改,那么就不要碰后端文件夹的任何文件;如果你只准备修改后台,就不要碰前台文件。

The OpenCart directory structure is based around two important parts of the OpenCart application. The frontend and the admin interface are each represented by a folder in the top level of your OpenCart installation. The frontend folder is called catalog/ and
the admin folder is called admin/. If you are making modifications only to the admin of an OpenCart store, you should not expect to modify any file within the catalog/ folder. If you are working on the frontend only, you should not be modifying the admin/
folder at all.

在admin/和catalog/ 文件夹下,你都可以发现模型、视图、控制器和语言这四个组件各自对应的文件夹。
在OpenCart安装还存在着其他几个文件夹。
系统文件夹中包含使用你的前台后台都要用到的类和函数。在这个文件夹中有电子邮件工具、数据库工具、控制器,模型及OpenCart引擎的其他部分,和库类的核心定义。当你需要修改OpenCart的功能时,你极少需要编辑这些系统文件。

Within each of the admin/ and catalog/ folders, you will find a folder for each of the Model, View, Controller and Language components of the OpenCart application. Several other folders exist in your OpenCart installation. The system folder contains classes
and functions used by both the admin and catalog areas of your store. Within this folder are email helpers, database helpers, the core definition of controllers, models and other parts of the OpenCart engine and library classes. When modifying OpenCart functionality,
you will seldom need to edit any of the system files.

image(图像)文件夹包含了所有通过图像管理器上传的图像。这些是你的产品图片,附加图片,以及OpenCart调整大小后的缓存图片。下载文件夹包含了产品相关的下载,它通过一个散列后缀,以避免恶意用户猜中文件名然后直接访问下载,因此你会发现你下载的文件名在该目录中都以随机字符串结尾。

The image folder contains all the images that are uploaded via the Image manager. These are your product images, additional images, and the cached versions of images that OpenCart has resized. The download folder contains any downloads associated with products.
Downloads are given a hashed suffix to avoid malicious users guessing the filenames correctly and accessing your downloads directly. This is why you will see random strings on the end of your download filenames
in this directory.

注解:
ORM
对象关系映射(英语:Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换。从效果上说,它其实是创建了一个可在编程语言里使用的“虚拟对象数据库”。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  opencart php MVC