General

  eZ Systems Website
  Technical documentation
  Editor documentation

This Documentation contains:
 
Technical documentation:



⚠ WARNING ! This documentation is deprecated !

Please go to the current Technical Documentation

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt
Note
titleVersion compatibility

This recipe is compatible with eZ Publish 5.2 / 2013.07

 

Table of Contents

Enhanced views for Content/Location

In some cases, displaying a content Content item/location Location via the built-in ViewController is not sufficient and will lead force you to do make many sub-requests in order to access different parameters.

...

  • Settings (either coming from ConfigResolver or ServiceContainer)
  • Current contentContent item's ContentType object
  • Current locationLocation's parent
  • Current locationLocation's children count
  • Main location Location and alternative locations Locations for the current contentContent item
  • etc…etc.

In those cases, you may want to use your own controller to display the current contentContent item/location Location instead of using the built-in ViewController.

...

Info

You can point to any kind of controller supported by Symfony (including controllers as a service).

The only requirement here is that your action method has a similar signature than  ViewController::viewLocation() or  or  ViewController::viewContent()  (depending on what you're matching of course). However, note that all arguments are not mandatory since Symfony is clever enough to know what to inject in into your action method . Hence That is why you aren're not t forced to mimic the ViewController's signature strictly. For example, if you omit $layout and $params arguments, it will still be still valid. Symfony will just avoid to inject injecting them in into your action method.

Original ViewController signatures

...

Warning
titleWarning on caching

Using your own controller,   it is your responsibility to define cache rules, like for every custom controller !

So don't forget to set cache rules and the appropriate  X-Location-Id header in the returned Response object.

See built-in ViewController for more details on this.

...

Tip
This is usually the recommended way to use a custom controller.
Note

Always ensure to that you add new parameters to existing $params associative array, using + union operator or array_merge() .
Not doing so (e.g. only passing your custom parameters array) can result with in unexpected issues with content preview. Previewed content and other parameters are indeed passed in $params.

...

Note

Always ensure to have a $params argument and to add new parameters to it, using + union operator or array_merge() .

Not doing so (e.g. only passing your custom parameters array) can result with in unexpected issues with content preview. Previewed content and other parameters are indeed passed in $params.

...

One other way to keep control on of what is passed to the view is to use your own controller instead of the built-in ViewController.

...