Message-ID: <297585745.2764.1485850732572.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2763_1990135610.1485850732572" ------=_Part_2763_1990135610.1485850732572 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Converting request parameters into API objects

Converting request parameters into API objects

=20
=20
=20
=20

Descriptio= n

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

Solution

For example:

=20
public function listBlogPostsAction( $locationId )
{
=09$location =3D $repository->getLocationService()->loadLocation( $lo=
cationId );
=20

Thanks to the param converter, you can directly have the API object at y= our 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:

=20
use eZ\Publish\API\Repository\Values\Content\Location;

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

Fur= ther information

If you want to understand how it works, you can check Symfony's param conver= ter documentation and the pull reques= t implementing the Repository ParamConverters.

Migrating your current application

See example pull request on the DemoBun= dle which provides a few concrete examples.

=20
=20
=20
=20

In this t= opic:

=20
=20
=20
------=_Part_2763_1990135610.1485850732572--