This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » eZ Publish 5 Platform » Customized ViewController

Customized ViewController

Customized ViewController

Thursday 25 April 2013 3:38:29 pm - 3 replies

Hi, I need some advice on best practice.

What do you think about customizing the standard ViewController

ezpublish.controller.content.view.class: eZ\Publish\Core\MVC\Symfony\Controller\Content\ViewController

with your own controller, extending the standard eZ controller?

The idea is to be able to customize the $param array passed to the view for a certain bundle. This is a minor thing, but templating in this bundle gets much simpler and more efficient. All you do is to move some common logic for all templates to the viewcontroller instead of creating a custom controller.

It works really nice, but since eZ 5 still is in a early phase, I imagine that the ViewController still could look at a change or two, and that could possibly lead to bugs when upgrading.

Anyone got some input?



Thursday 25 April 2013 4:08:14 pm

Hello Kristian

Extending the ViewController is indeed possible since it's defined as a service, but it's a bad practice. It's like using a bazooka to hunt a fly blunk.gif Emoticon.

There is  an open issue on that topic, with a pull-request that is still under discussion. Feel free to comment and explain your use case since I need help to push this for 5.2 happy.gif Emoticon.

Anyway, the pull request is based on a existing feature you can use : the PreContentView event. You can define a listener for it and add any additional variables you need. However, beware that the event is triggered every time the ViewManager is called to render a content/location/block, so you should be careful on the conditions you want to match for injecting variables. The pull-request addresses this issue by adding configuration sugar, bound on the template selection rule.

Thursday 25 April 2013 4:17:57 pm

Thanks Jerome!

Really valuable feedback. Will dig into it!

Tuesday 30 April 2013 8:14:09 pm


My concrete usecase for this is that I have a "read only" database table, related to content objects in eZ, and those data must be available for every full view of the content object.

1. I do not want to create a "fetch" function in twig

2. I do not want to create custom controllers to render objects if I dont have complex view logic

One of the issues I see by the approach of overriding the view content service or creating a PreContentView event, is of course related to performance. For this case, that will be handled by using Stash or some other cache api on top of memcached.

I dont know how smart it would be cache-wise (thinking about eZ/Symfony cache), but I could also see that global data like menus/navigation easily could be generated and cached in the PreContentView function.



Modified on Tuesday 30 April 2013 8:15:13 pm by Kristian Blom


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from