eZ Community » Blogs » Jean-Luc Chassaing » How one should code in eZ Platform


Jean-Luc Chassaing

How one should code in eZ Platform

Monday 11 June 2018 10:18:13 pm

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

Some eZ Platform devs are old ez legacy devs. Some of them (like me) started building eZ websites on 3.x releases. The thing is they have bad old habits and they tend to keep building ezPlatform projects on a legacy way of doing things. But that's a bad path. After taking some time on a eZ 5.x and eZ Enterprise projects here is what I found out.

I / code structure

In legacy world

In the old days, when you had a web site to build, a good idea would be to make many extensions. Extensions where easy to build and easy to manage. If the project had multiple accesses you could have extensions for each access and load them in each access ini conf  file so that extension one build for access one would not interfere with extension two loaded in access two.

Let say you were building a rather simple website with articles images, well, just simple content. But then you had to deal with a more complex content which required adding some module, specific views well you then decided to add a new extension and that was a good idea.

In eZ Platform

Don't forget that eZ Platform is build on symfony. In the symfony world a loaded bundle is loaded. So you'll have to structure the web site differently. You can use environments to load bundles for specific accesses but that's not a good idea.

If you don't intend to share your code just make one single bundle. But then you'll have to organize your code or it won't be easy for an other dev to find out what on hell you intended to do with out going true a full code analysis. Name things and structure them for what they do.

2 / layer separation

In legacy world

In legacy world you could make fetch's in templates. That was really useful thus really ugly. Say you were writing a folder template file. In one line of template code, you could fetch the node children, array walk the result and display them. That was rather useful and limited the php writing code part of the job but that was not really MVCish.

In eZ Plaform

So please don't try to recreate does horrible tpl fetch functions by creating twig extension to fetch a location child contents. A twig extension should be used only to do a simple string or data formatting and that's all. If there's some data you need in your template call it threw a Controller or a QueryType before loading your template but please do not add a twig extension that will make use of contentService, locationService or worse SearchService.

3 / knowing what Symfony is

You guys won't be good efficient apps if you don't understand the symfony world.The base action tool in symfony is the controller it could be compared to the ez legacy modules. A controller is a class.

A controller can be container aware build extending the base controller that will have a bunch of methods to access the repository of container. So building a controller that way will easily give you access to other services.

The containerAware way of building controllers is not that good solution. A good way would be to make it a service and only load what you need. And that will be way much easier to do in ezplatform 2.

So please make a choice but do not build a controller as a service and extend the defaultController.


That's all for now.
maybe I'll figure out much things to say here

Proudly Developed with from