Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Php Calls In Controllers Or Templates Rate Topic   - - - - -

 
  • natewallis
  • Advanced Member
  • Members
  • Join Date: 11-Jan 13
  • 148 posts

Posted 03 August 2018 - 12:07 AM #1

Hi, 

 

I am working on a new theme for our website.

 

I have been placing all of my calls for template variables in my addon controllers versus the smarty templates.  Which is working fine and resulted in very clean template files.  I guess in the strict definition, controllers is probably where these calls belong.

 

Does this have any impact on caching performance of the pages?   I wouldn't have thought so, but I am not quite aware of the smarty internals and how that all works.  Either way the functions are called right?

 

Later on, I will look at full page caching for my site, so the calls should be minimised as much as possible.  

 

Just want to make sure I am not painting myself into a corner :)



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18498 posts

Posted 03 August 2018 - 07:25 AM #2

Yes, your solution is right. In ideal CS-Cart templates should not have any calls of php functions and CS-Cart team is working on it


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11023 posts

Posted 03 August 2018 - 08:19 PM #3

Yes, think of a standard 3-tier architecture (backend (DB), business rules and presentation).

 

Any "data" should be addressed in the business rules layer (PHP controllers in this case) and the data should be "used" in the presentation layer.

 

While smarty supports variable modifiers (I.e. {"foo"|bar} ) they should generally NOT be used for other than data formatting (of which many are smarty builtin functions, not php functions).

 

Regarding caching, template variables become PHP variables in the cached smarty templates.  Hence the value of those variables is determined dynamically and the values are not cached.  Smarty assumes that if you're using a "variable" versus a constant, that the variable might change for different views of that page based on the business rules and therefore the values are determined at runtime.  However, the layouts (html) are effectively cached.

 

Hope that provides further clarity.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.