Use functions in templates

I. List of model variables
II. Syntax used
III. List of shared functions
IV. Special functions

In addition to using Laravel standard functions and variables,
SCart provides new variables and functions to support the template programmers.
Purpose:

- Separate the template maker and the developer: No need to have much knowledge of code in models and controllers.
- The model variable and its functions are called in any view: No need to declare in each controller for each view
- Syntax uniformity

Note:
Of course, these functions you absolutely can use in places other than the view (template)

I. Model variables are initialized:
1. $modelProduct -> model Product
2. $modelCategory -> model Category
3. $modelBanner -> model Banner
4. $modelBrand -> model Brand
5. $modelSupplier -> model Supplier
6. $modelNews -> model News
7. $modelPage -> model Page
8. $modelCmsCategory -> model CMS Category
9. $modelCmsContent -> model CMS Content
10. $modelUserProfile -> model profile user login
11. $modelUserOrder -> model order user login

II. Syntax used:

$biến_model->start()->(get)group-query->(set)query->getData()|getSql();

Example:
$modelProduct->start()->getProductHot()->setLimit(20)->setPaginate()->setRandom()->getData();

Note:
- Group-query:
Essentially, many predefined queries
- Query:
Additional conditions. If it matches a query group-query, the following query will overwrite the previous query.
- getData | getQuery
Equivalent to get () and toSql () functions in Laravel
- start()
To avoid returning unexpected results, you should use the start () function before you start processing data.

 III. Functions that support common to all model variables:
  • start(): Start using the model functions
  • setLimit(int) // The result limit is limited -> The following function replaces the previous one
  • setSort([$key, ‘asc|desc’]) //ort returned results -> Used many times
  • setRandom(0|1) // Activating random fetches results returns -> The following function replaces the previous function
  • setPaginate() // Activate pagination mode
  • setMoreWhere([$v1, ‘<|>|=|like|<=|>=|<>’, $v2]) // dditional where clause -> Used multiple times
  • getQuery() // Trả về câu truy vấn -> Called last.
  • getData() // Trả về kết quả dữ liệu -> Called last.
  • getDetail($id) // Trả về kết quả chi tiết 1 model thông qua $id -> Called last.

IV. Special functions:
1. $modelProduct
  • setKeyword($string) // serach product with key word : sku, name, description, keyword
  • getProductNew() // get product type is new
  • getProductHot() // get product type is hot
  • getProductBuild() // get product is bundle
  • getProductGroup() // get product is group
  • getProductSingle() // get product is single
  • getProductToCategory($arrCategory | int) // get products in array category
  • getProductToBrand($arrBrand | int) // get products in array brand
  • getProductToSupplier($arrSupplier | int) // get products in array supplier
  • getProductLatest() // get products latest
  • getProductLastView() // get top products last view
  • getProductBestSell() // get top products best sell
  • getProductPromotion() // get top products promotion
2. $modelCategory
  • setParent(int) // replace before 
  • getCategoryRoot() // get category parent = 0
  • getCategoryTop() // get category have top = 1
3. $modelBanner
  • getBanner() // get Banner
  • getBackground() // get Background
4. $modelBrand
//
5. $modelSupplier
//
6. $modelNews 
//
7. $modelPage
//
8. $modelCmsCategory
  • setParent(int) // replace before 
  • getCategoryRoot() // get category parent = 0
  • getCategoryTop() // get category have top = 1
9. $modelCmsContent
  • getContentToCategory($arrCategory | int) // get contentin array category
10. $modelUserProfile
//
11. $modelUserOrder
  • getOrderNew() // status 1
  • getOrderProcessing() // status 2
  • getOrderHold() // status 3
  • getOrderCanceled() // status 4
  • getOrderDone() // status 5
  • getOrderFailed() // status 6

Related topics