[NFR] Separate variable spaces in view
Hello,
I think that it would be very usable feature to implement variable spaces in views. Imagine, you have many paginators with same styles, everything on different pages. Best practice is to make reusable view, let me call it paginator.phtml.
So, in simple example if would look like this:
// view context
<?php $paginator = $model->getPaginator(); ?>
<?php $this->partial('layouts/partials/paginator') ?>
paginator.phtml will use variable $paginator from the global scope. But what if.. i need 4 paginators on the same page? Sure, i can repeat this code many times, but.. i would propose zend implementation here, have a look:
$this->partial('layouts/partials/paginator', [
'paginator' => $paginator,
])
In this case, partial view will have only 1 variable: $paginator. And it will be much more reusable.
:+1: It's a good idea
It will be very useful!
Nice decision.
By the way, perhaps Phalcon\Mvc\View::getRender() makes the same, what is the difference between those two methods?
As far as I understand:
getRender() is render all the view hierarchy related to the some controller/action view
and partial() just render some single view
@Agent-J I thought this should be done by render() method... According to docs, we have two same methods, render() and getRender(). Method names and descriptions are very confusing :(
Even with docs it is hard to understand what actually method does.
render() executes render process from dispatching data while getRender() takes the data as parameters and return the output as a string.
UPD: I was a bit wrong. getRender() is just a wrapper of view start->render->finish->getContent
Check the docs examples
This is implemented in 1.2.0
@phalcon Thanks a lot!
This issue reappeared in 3.0.1 with php7.