-
Notifications
You must be signed in to change notification settings - Fork 61
Updates in Helper\Navigation\Breadcrumbs.php and Menu.php #7
Conversation
Added possibility to set parameters(variables) for partial to populate in the view. In the current version there is no possibility to transmit variables into partial view , you can only set partial and module like this: $this->navigation('navigation') ->menu() ->setPartial('partial/yourPartial.phtml','yourModule') so with this update you can simply set those variables like this: $this->navigation('navigation') ->menu() ->setPartial('partial/yourPartial.phtml','yourModule') ->setPartialParams(array('variableName' =>$variable)); That's all.
Update in Helper\Navigation\Menu.php
Added possibility to set parameters(variables) for partial to populate in the view. In the current version there is no possibility to transmit variables into partial view , you can only set partial and module like this: $this->navigation('navigation') ->breadcrumbs() ->setPartial('partial/yourPartial.phtml','yourModule') so with this update you can simply set those variables like this: $this->navigation('navigation') ->breadcrumbs() ->setPartial('partial/yourPartial.phtml','yourModule') ->setPartialParams(array('variableName' =>$variable)); That's all.
Update in Helper\Navigation\Breadcrumbs.php
👎
|
@froschdesign From reading the description, I think the reporter wants to be able to pass arbitrary parameters to the partial, not just menu options. @Zyqsempai Please add unit tests, and also run |
@weierophinney |
|
Can you provide a use case? |
Hi , here is use case from my current project, |
Update Menu.php
Update MenuTest.php
Updates Breadcrumbs.php
Added unit test for setter and getter for PartialParams , also fixed all issues with php-cs-fixer. |
Show or not? You can use the custom page properties: $page1 = new Zend\Navigation\Page\Mvc();
$page1->header = true;
$page2 = new Zend\Navigation\Page\Mvc();
$page2->footer = true; I'm not entirely against this PR, but I think there are too many options in the navigation view helpers.
|
This is an alternative implementation to zendframework#7, but only in the `Menu` helper. The idea is to introduce a new render method, instead of adding more state to the helper.
I like the general idea (passing variables to the partial). However, I'm not convinced by the implementation. Typically, I suspect I'd want to pass parameters to the partial on a case-by-case basis, at the time of invocation — in other words, I wouldn't want stateful parameters. As such, I'm wondering if this should warrant an alternate rendering method instead of additional helper properties — something like this: echo $this->navigation()->menu()->renderPartialWithParams(['flag' => $flag]); The signature would be: public function renderPartialWithParams(array $params = [], $container = null, $partial = null) I've provided a "sketch" if the idea here: weierophinney@8091297 @froschdesign — what do you think of this approach? |
@weierophinney |
@Zyqsempai Do you want to take it from here? or would you like me to do a competing PR? |
@weierophinney, What do you mean, "to take it from here"? |
Personally I think the method name indicates how it should be implemented: The suggested implementation makes me think about methods like |
@Martin-P The problem is that public function renderPartial($container = null, $partial = null) These are both null by default, and the method does some work to auto-determine them if they are not present. Considering the standard use case is to pass no arguments, adding the parameters as an option to the end makes the method unwieldy: echo $this->navigation->menu()->renderPartial(null, null, ['flag' => $flag]); This is why I suggested adding a new method, putting the argument at the start. @Zyqsempai — by "take it from here," I was inviting you to re-factor your patch to follow the direction I was providing. :) I haven't written tests, as I just wanted to demonstrate how I'd approach it, so you'd need to:
You can then push to this same pull request. I'd recommend starting from a fresh branch, and then force-pushing to the original branch on your github fork. |
@weierophinney , Thank you for your invitation, i will start it tomorrow. |
@weierophinney I understand your point, but isn't it more intuitive to keep the method more like the regular partial view helper? At this moment when I want to use Looking at echo $this->navigation->menu()->renderPartialWithParams(
['flag' => $flag],
null,
'myPartial.phtml'
); So perhaps it is better to ommit the public function renderPartialWithParams($partial = null, array $params = []) And looking at this... I can't ignore the possibility to introduce a BC break instead of creating new methods and change the signature for public function renderPartial($partial = null, array $params = []) I am aware it is a BC break, but I think this is a better approach instead of creating fixes because of something that can possibly be called a design flaw? |
@Zyqsempai I'm trying to keep the order of the arguments internally consistent in the helpers. Since the |
Please close this PR. It was merged with #8. |
ping @weierophinney |
Added possibility to set parameters(variables) for partial to populate in the view.
In the current version there is no possibility to transmit variables into partial view , you can only set partial and module like this:
so with this update you can simply set those variables like this:
That's all.