General

  eZ Systems Website
  Editor documentation


  Developer documentation

  Back to the top

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: layout

Description

In lots of cases, a request will provide a contentId or a locationId. Before using them, you will have to load API object within your controller.

Solution

For example:

Code Block
languagephp
public function listBlogPostsAction( $locationId )
{
	$location = $repository->getLocationService()->loadLocation( $locationId );

Thanks to the param converter, you can directly have the API object at your disposal. All you have to do is:

  • For Locations:
    • In your controller's signature, type int the variable to Location.
    • Make sure a parameter named "locationId" is provided by the request.
  • For Content items:
    • In your controller's signature, typeint the variable to Content
    • Make sure a parameter named "contentId" is provided by the request

Example

Example using Locations:

Code Block
languagephp
use eZ\Publish\API\Repository\Values\Content\Location;

public function listBlogPostsAction( Location $location )
{
	// use my $location object

Further information

If you want to understand how it works, you can check Symfony's param converter documentation and the pull request implementing the Repository ParamConverters.

Migrating your current application

See example pull request on the DemoBundle which provides a few concrete examples.

In this topic:

Table of Contents
maxLevel3