eZ Community » Forums » eZ Publish 5 Platform » LegacyKernel Callback initialised N...
expandshrink

LegacyKernel Callback initialised N times inside loop

LegacyKernel Callback initialised N times inside loop

Thursday 23 October 2014 2:53:15 pm - 1 reply

Hey, 

Problem 1:

I'm using the LegacyKernel::runCallBack() to work with some custom contentTypes in the Symfony stack. I'm using the eZURI::transformURI() function to transform URI's to real links. The problem I'm having is that this operation is done inside a loop, and thus creating over 1400 Legacy kernels, if I understand the problem correctly. How can I generate the kernel once and reduce memory usage and execution time? 

The code I'm using as a gist:

https://gist.github.com/thomaslarsson/5f20adfe04a7efea2ab6

Problem 2:

Another problem I'm having is with image-urls. As I work with old legacy nodes, I'm not sure how to correctly get the full image URL. I'm currently using the following code, and I belive it has to be a better way:

$xml = new \SimpleXMLElement($dataMap['image']->DataText);

$imageUrl = (string) $xml->attributes()->url->__toString();

Thanks in advance

Modified on Thursday 23 October 2014 2:57:48 pm by Thomas Maurstad Larsson

Thursday 23 October 2014 4:25:57 pm

Hi Thomas

1. Why are you using LegacyKernel for this?

2. You should not use legacy kernel to generate URLs. Inject the router instead and use generate() method:

// If you have the Location object
$url = $this->router->generate( $location );
 
// If you only have the locationId (formerly known as nodeId)
$url = $this->router->generate( 'ez_urlalias', array( 'locationId' => $locationId ) ); 
expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from