zendframework / zend-expressive-zendviewrenderer

zend-view PhpRenderer integration for Expressive
BSD 3-Clause "New" or "Revised" License
11 stars 12 forks source link

Question : addDefaultParam / addParam #5

Closed harikt closed 7 years ago

harikt commented 9 years ago

Recently I need to use certain variables in almost every places. One thing I noticed , you can add via addDefaultParam method.

$this->renderer->addDefaultParam($templateName, $param, $value);
  1. I got some feedback that the name is default, but the variable we were adding was not default value. But the original value. Is there any reason to keep the name addDefaultParam rather than addParam .
  2. Is there a way we can set parameters not by setting the template name ? Because these variables need to be used at many other templates.

If the question is not appropriate to be an issue. Let me know where I should ask.

Thank you.

weierophinney commented 9 years ago

@harikt —

I got some feedback that the name is default, but the variable we were adding was not default value. But the original value. Is there any reason to keep the name addDefaultParam rather than addParam .

Who gave you that feedback? What was their rationale?

We called these "default" parameters, because they will be used unless an override is provided. "Default" is reasonable terminology for this scenario.

Is there a way we can set parameters not by setting the template name ? Because these variables need to be used at many other templates.

Yes: use TemplateRendererInterface::TEMPLATE_ALL, or the string *; that indicates that the variable is to be used as a default for any requested template, vs a single named template.

harikt commented 9 years ago

Who gave you that feedback?

I was talking with a developer and showing the code how to achieve some things.

What was their rationale?

Default seems when something is not there, the value is default value. Eg mostly about the default use case

// if no $_GET['page'] = 5 return 1
$this->getQuery('page', 1); 

I did felt the same when the terminology default was there.

I don't know what I can call this, but it is not default, but a permanent value which we don't expect to change.

$this->users = new SomeUserCollection();

The fact is we don't expect $this->users like this to change. You may ask me why not pass it over the render call. But this is just an example.

Thank you for the explanation about the usage of all variables.

I will try to point to the discussion.