We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Rendering view script hierarchy - fetching current level in event listener

Hi all,

My question is about Hierarchical Rendering and View rendering Events.

I'm rendering a hierarchy of Main View -> Controller View -> Action View and I'm attaching View event listener using the following code:

$eventsManager->attach('view', function($event, $view) {
    if ('afterRenderView' == $event->getType()) {
        // Append length of rendered content.
        $content = $view->getContent();
        $content .= PHP_EOL . '/* Content length: ' . strlen($content) . 'b */' . PHP_EOL;
        $view->setContent($content);
    }
});

I know that I can set rendering levels using LEVELACTION* set of constants (values of 1 through 5).

What I'm trying to do there is append the length of all rendered views. But the problem is, I need to do it only when I receive "afterRenderView" on "Controller View" level. I cannot attach to "afterRender" event, since by that time, the entire hierarchy has been rendered, and I only want to inject length summary after "Controller View" is done rendering (please don't ask why).

So, what I need in $view is a method like getCurrentLevel() that would return current LEVELACTION*.

Can this be done in some other way? If not, how can I submit a modest request for this feature.

Thanks, Temuri



98.9k

There is no such option to get the current render level inside a plugin, if you want you can create a new NFR on Github



51.4k

Thanks.

https://github.com/phalcon/cphalcon/issues/907

Please let me know if it's not clear enough!

Keep up the great work.