cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[NFR] Separate variable spaces in view

Open alvassin opened this issue 13 years ago • 10 comments

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.

alvassin avatar May 20 '13 09:05 alvassin

:+1: It's a good idea

iforp avatar May 20 '13 10:05 iforp

It will be very useful!

mlanin avatar May 27 '13 08:05 mlanin

Nice decision.

CAMCOH1989 avatar May 27 '13 08:05 CAMCOH1989

By the way, perhaps Phalcon\Mvc\View::getRender() makes the same, what is the difference between those two methods?

alvassin avatar May 27 '13 12:05 alvassin

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

iforp avatar May 27 '13 13:05 iforp

@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.

alvassin avatar May 27 '13 14:05 alvassin

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

iforp avatar May 28 '13 08:05 iforp

This is implemented in 1.2.0

ghost avatar Jun 07 '13 05:06 ghost

@phalcon Thanks a lot!

alvassin avatar Jun 07 '13 11:06 alvassin

This issue reappeared in 3.0.1 with php7.

seliver avatar Feb 01 '17 13:02 seliver