eZ Community » Forums » eZ Publish 5 Platform » Best practice to get the first...
expandshrink

Best practice to get the first children node id of a specific node in a Controller

Best practice to get the first children node id of a specific node in a Controller

Monday 07 July 2014 2:31:52 pm - 4 replies

Hi,

There is a best practice to get the first children node id of a specific node ?

I try to use my $pager result, but it's a big variable to use :/

Thanks

Djoo

Monday 07 July 2014 2:56:19 pm

Hi

I would suggest using LocationService::loadLocationChildren which retrieves the children of a given location. Intended mainly for the admin interface, it honors sorting, but lacks filtering, but should suit your needs well.

Cheers,
Donat

Monday 07 July 2014 3:46:15 pm

Thanks

This is my code :

 $firstChildrenNodeId = $repository->getLocationService()->loadLocationChildren($locationParent)->locations[0]->contentInfo->mainLocationId;

Monday 07 July 2014 4:22:38 pm

Hi

you can have it shorter and at the same time more efficient and robust:

 $firstChildrenNodeId = $repository->getLocationService()->loadLocationChildren($locationParent,0,1)->locations[0]->id

loadLocationChildren returns a list of locations. You can limit the number of locations to return. No need to go through contentInfo which may lead you to the wrong location id in case of multiple locations for the same content.

Cheers,
Donat

Tuesday 08 July 2014 11:13:51 am

Thanks for the tips happy.gif Emoticon

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from