Share » Learn » eZ Publish » Understanding and developing fetch...

Understanding and developing fetch functions

Tuesday 14 September 2010 4:41:06 am

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

When to create a fetch function ?

When working your eZ project, you may ask yourself a few questions :

  • What is the difference between a fetch and a template operator ?
  • When do I need to create a fetch function ?

Well, let's try to answer those vital questions ;-).

 

Difference between a fetch and template operator

Well, that's right, the difference is thin as both can suit you in many situations. Here are significant differences :

  1. Fetch functions can also be called from PHP while this can be difficult for template operators
  2. You should consider a template operator as a data modifier (string or array operations for example), while this is not strictly the case for all built-in operators.
  3. You can consider a fetch function as a model call in a MVC pattern.
  4. Fetch functions can substantially reduce the amount of template code and increase its readability by transferring complex code from template to your PHP fetch function.
  5. Fetch functions are much easier to implement :)
 

When to create a fetch function

Basically, you will need to develop a fetch function when you need to look for some data in your database, on your file system, in a partner's webservice... This is the main role for this feature, but not only. Indeed, as I said above, with fetch functions you can drastically reduce template code complexity.

Did you ever get bored of maintaining template code ? Have you ever dreamt of breakpoints driven debug instead of crappy attribute( 'show' ) ? Well, as a fetch function is written in PHP, you can transfer all your complex template code into a real function, get rid of template language limitations and take fully advantage of the real eZ Publish framework power. And of course, your fetch result can fully be exploited in your templates, so you can aggregate your data into an array, or even into PHP objects (but for that, you will need to implement some methods in your returned object's class; see the appendix for more explanations).

 
36 542 Users on board!

Tutorial menu

Printable

Printer Friendly version of the full article on one page with plain styles

Author(s)