Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFR] Fetch current View render level in the events attached to Phalcon\Mvc\View #907

Closed
temuri416 opened this issue Jul 24, 2013 · 2 comments

Comments

@temuri416
Copy link
Contributor

  1. Phalcon\Mvc\View supports hierarchical view rendering:

Main View -> Controller View -> Action View

  1. Phalcon\Mvc\View emits event view to which I can attach a listener:
$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 want to be able to retrieve current View::LEVEL_ACTION_* in my event handler to be able to branch necessary action depending on the combination of current level in hierarchy and type of event:

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

Feature Request

Implement $view->getCurrentLevel().

@temuri416
Copy link
Contributor Author

@sjinks

I think what you have implemented is a getter for the value set by:

\Phalcon\Mvc\View::setRenderLevel()

In this ticket I was asking for a getter method for current level that's being rendered by the View.

Do you think that can also be done?

Thanks!

@temuri416
Copy link
Contributor Author

Confirmed - works as expected. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant