cs-cart-控制器
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Controllers –控制器
发表于2012 年4 月16 日
Controllers 控制器
Basic schema of the software functioning consists in calling one of the two main executable PHP files (admin.php or index.php) and further consecutive execution of PHP files implementing the program functionality. 软件运行的基本模式是调用两个主程序PHP文件(admin.php或index.php)之一,然后通过进一步连续执行其它的PHP文件来实现程序功能。
1. index.php 或 admin.php ->
2.prepare.php ->
3. init.php ->
4. [controller_name].php
In CS-Cart terms a file connected under number four is named a controller. Data handling in the program is performed in this file – extracting the necessary data from the database, data handling, calculations, transformations, etc. and preparation of the data for further display. 在CS-Cart规则中,上述第4项中被连接的文件被叫做控制器。程序通过这个文件实施数据处理—包括从数据库中提取必要的数据、数据处理、计算、转换等,并为进一步显示准备数据。
A path to the controller and its name are defined by the program automatically based on the value of the “dispatch” parameter, which was passed to the main executable file. The “dispatch” parameter has the following format “[controller_name].[mode_name]“, where “[controller_name]” –is a name of the controller, and “[mode_name]” – mode in which the called controller will work. The name of the called file will be “[controller_name].php”.
通过传递给主程序文件”dispatch”参数的值,程序可以自动定义到控制器的路径和它的名称。”dispatch”参数格式为
“[controller_name].[mode_name]“,其中“[controller_name]“是控制器名称,“[mode_name]” 为所调用控制器的运行模式。调用的文件名将
是”[controller_name].php”。
All controllers for the admin panel (executable file – admin.php) are located in the “/controllers/admin” directory, for the customer area (index.php) –in the “/controllers/customer” directory. If the called controller is not in these directories, then the system tries to launch it from “controllers/common”. This is d one for the situations when the same controller is to serve the customer and administrator areas and its function is the same for both areas.
所以针对管理面板(执行文件– admin.php)的控制器都位
于”/controllers/admin”目录,针对客户区域 (index.php)的控制器都位于“/controllers/customer”目录。如果调用的控制器不在这两个目录,系统将尝试从”controllers/common”目录读取。这是为了处理同一个控制器同时为客户区域和管理员区域服务并且该控制器对两个区域功能一致的情况。
Controller connection is carried out by the function
[/core/fn.control.php]/fn_dispatch(), which does not accept any parameters and performs the following main actions:
控制器连接通过函数 [/core/fn.control.php]/fn_dispatch()进行,该函数不接受任何参数并实施以下主要动作:
1.Checks for validity the parameter “dispatch”.
检查参数“dispatch”有效性。
2.Checks permissions of the current user for the called controller.
检查当前用户是否具有所调用控制器的权限。
3.Redirects to a secure protocol (HTTPS) when necessary.
如有必要,重定向至安全协议(HTTPS) 。
4.Prepares an ordered list of precontrollers and postcontrollers (from addons and the core)
for consecutive connection in the right order.
为继续连接准备一个正确顺序的前控制器和后控制器(来自插件和核心)清单。
5.Automatically defines a template to display.
自动定义一个显示用的模板。
Example 1.
We have the value of the parameter “dispatch=products.manage” and the executable file “admin.php” or in other words enter
“http://cscart_dir/admin.php?dispatch=products.manage” in the address bar of the browser.
参数值”dispatch=products.manage” ,执行程序为”admin.php”,即在浏览器地址栏输入”http://cscart_dir/admin.php?dispatch=products.manage”。
The connected controller will be located at the following path –
“/controllers/admin/products.php”. The parameter “manage” will be used within the file to define actions that controller must perform with the data. In this example “manage” indicates that the controller should select a list of products from the database and display it on the products page in the administrator area.
将连接的控制器路径为”/controllers/admin/products.php”。参
数”manage”将用来定义控制器对数据实施的动作。在这个例子里
面,”manage”指出控制器将从数据库中选择一些产品并将其显示在管理员区域的产品页面。