正在加载
请稍等

菜单

红楼飞雪 梦

15526773247

文章

Home prestashop Controllers within PrestaShop
Home prestashop Controllers within PrestaShop

Controllers within PrestaShop

prestashop by

In an MVC architecture, a Controller manages the synchronization events between the View and the Model, and keeps them up to date. It receives all the user events and triggers the actions to perform.
If an action needs data to be changed, the Controller will “ask” the Model to change the data, and in turn the Model will notify the View that the data has been changed, so that the View can update itself.

在MVC架构中,控制器负责管理视图和模型之间的同步事件,并让他们及时更新。它接收所有的用户事件和触发要执行的操作。如果一个动作需要的数据进行更改时,控制器将要求的模式来改变数据,进而该模型将通知视图,该数据已被更改,然后视图将自动更新

All of PrestaShop’s controllers actually override the Controller class through another inheriting class:

  • AdminController,
  • ModuleAdminController,
  • FrontController,
  • ModuleFrontController,

They can be found in the /classes/controller folder.

The FrontController class

Here are some of the class’ properties:

Property
Description
$template Template name for page content.页面内容对应的模板名称
$css_files Array list of CSS files.
css文件的数组列表
$js_files Array list of JavaScript files.javascript文件的数组列表
$errors Array of errors that have occurred.已经发生的错误存储在这个数组里
$guestAllowed Whether a customer who has signed out can access the page.当客户注销后是否允许访问页面
$initialized Whether the init() function has been called. 

init() 函数是否已经被调用

$iso The ISO code of the currently selected language. 

当前选择的语言的ISO代码。

$n The number of items per page. 

每页的项目数

$orderBy The field used to sort.该字段用来排序
$orderWay Whether to sort is ascending or descending (“ASC” or “DESC”)
是使用升序方式还是降序方式排序
$p The current page number.当前页号。
$ajax If the ajax parameter is detected in request, set this flag to true.如果ajax参数在检测请求,设置该标志为true。

Execution order of the controller’s functions

  1. __contruct(): Sets all the controller’s member variables.    为所有所有控制器的成员变量赋值,构造函数
  2. init(): Initializes the controller.    初始化控制器
  3. setMedia() or setMobileMedia(): Adds all JavaScript and CSS specifics to the page so that they can be combined, compressed and cached (see PrestaShop’s CCC tool, in the back office “Performance” page, under the “Advanced preferences” menu).     将所有的JavaScript和CSS具体到页面,使他们可以合并,压缩和缓存(见的PrestaShop的CCC工具,在后台“性能”页面,在“高级首选项”菜单)。
  4. postProcess(): Handles ajaxProcess. 处理ajaxProcess
  5. initHeader(): Called before initContent().    在initContent()之前调用,设置页面头部
  6. initContent(): Initializes the content.    初始化内容
  7. initFooter(): Called after initContent().    在initContent()之后调用,设置页面尾部
  8. display() or displayAjax(): Displays the content.    显示页面内容

Existing front office controllers    现有的前端办公控制器

Here is the default controllers, and the theme files that use them .

这里是默认的控制器,以及使用它们的主题文件。

Controller’s filename
Description
AddressController.php Used by address.php to edit a customer’s address.

使用address.php编辑客户的地址。

AddressesController.php Used by addresses.php to get customer’s addresses.

使用addresses.php获得客户的地址。

AttachmentController.php
AuthController.php Used by authentication.php for customer login.

 

使用authentication.php来让客户登录。

BestSalesController.php Used by best-sales.php to get best-sellers.

 用best-sales.php获得畅销。

CartController.php Used by cart.php to manage the customer’s cart.

 

使用cart.php来管理客户的购物车

CategoryController Used by category.php to get product categories.

 

使用category.php获得的产品类别

ChangeCurrencyController.php
CmsController.php Used by cms.php to get a CMS page.

 

使用cms.php得到一个CMS页面

CompareController.php Used by products-comparison.php to compare products.

 

使用products-comparison.php产品比较产品

ContactController.php Used by contact-form.php to send messages.

 

用于contact-form.php的发送邮件

DiscountController.php Used by discount.php to get a customer’s vouchers.

 

使用discount.php得到客户的优惠券

GetFileController.php
GuestTrackingController.php Used by guest-tracking.php to manage guest orders.

 

使用guest-tracking.php来管理用户订单

HistoryController.php Used by history.php to get a customer’s orders.

 

使用history.php来获取用户订单

IdentityController.php Used by identity.php for customer’s personal info.

 

对于客户的个人信息使用identity.php

IndexController.php Used by index.php to display the homepage.

 

使用index.php来显示首页

ManufacturerController.php Used by manufacturer.php to get manufacturers.

 

使用manufacturer.php得到厂家信息

MyAccountController.php Used by my-account.php to manage customer account.

 

用my-account.php来管理客户账户

NewProductsController.php Used by new-products.php to get new products.

new-products.php获得新产品

OrderConfirmationController.php Used by order-confirmation.php for order confirmation.

使用confirmation.php来确认订单

OrderController.php Used by order.php to manage the five-step checkout.

 

使用order.php管理五步结帐

OrderDetailController.php Used by order-detail.php to get a customer order.

 

使用订单detail.php获得客户订单

OrderFollowController.php Used by order-follow.php to get a customer’s returns.

 

使用订单follow.php得到客户的反馈(可能是订单评价信息)

OrderOpcController.php Used by order-opc.php to manage one-page checkout.

 

使用order-opc.php管理单页结帐

OrderReturnController.php Used by order-return.php to get a merchandise return.

 

使用order-return.php来获得商品反馈

OrderSlipController.php Used by order-slip.php to get a customer’s credit slips.

 

 

使用order-slip.php来获取用户的信贷卡单

PageNotFoundController.php Used by 404.php to manage the “Page not found” page.

 

使用404.php来管理”Page not found”页面

ParentOrderController.php Manages shared order code.

 

管理共享订货代码

PasswordController.php Used by password.php to reset a lost password.

 

使用password.php来重置已经忘记的密码

PdfInvoiceController.php
PdfOrderReturnController.php
PdfOrderSlipController.php
PricesDropController.php Used by prices-drop.php to get discounted products.

 

使用prices-drop.php来获得打折产品

ProductController.php Used by product.php to get a product.

 

使用product.php得到的商品

SearchController.php Used by search.php to get search results.

 

使用search.php来获得搜索信息

SitemapController.php Used by sitemap.php to get the sitemap.

 

使用sitemap.php获得网站地图

StatisticsController.php
StoresController.php Used by stores.php to get store information.

 

使用stores.php获得商店信息。

SupplierController.php Used by supplier.php to get suppliers.

 

使用supplier.php获得供应商

 

Overriding a controller

Thanks to object inheritance, you can change a controller’s behaviors, or add new ones.

Keep overrides for your own shop

Overrides in PrestaShop are exclusive. This means that if your module overrides one of PrestaShop’s behaviors, another module will not be able to use that behavior properly, or override it in an predictable way.

Therefore, overrides should only be used for your own local modules, when you have a specific need that cannot be applied with it.

It is not recommended to use an override in a module that you intend to distribute (for instance through the PrestaShop Addons marketplace), and they are forbidden in partner modules.

PrestaShop’s controllers are all stored in the /controllers folder, and use the “Core” suffix.

For instance, when working with the Category controller:

  • File: /controllers/CategoryController.php
  • Class: CategoryControllerCore

In order to override a controller, you must first create a new class without the “Core” suffix, and place its file in the /override/controllers folder.

For instance, when overriding the Category controller:

  • File: /override/controllers/front/CategoryController.php
  • Class: CategoryController

 

02 2015-08

 

我要 分享

 

 

本文 作者

 

相关 文章