Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Allow passing objects to the url helper #4178

Merged
merged 4 commits into from
Apr 12, 2013
Merged

Allow passing objects to the url helper #4178

merged 4 commits into from
Apr 12, 2013

Conversation

macnibblet
Copy link
Contributor

Heya peeeps!

I can't be the only person that hates doing

echo $this->url('route', array('id' => $model->getId(), 'slug' => $model->getSlug()));

since they map directly it would be nice to just do

echo $this->url('route', $model);

An idea would also be to check if the model/entity has a toArray method if the ArrayUtils fails.

@macnibblet macnibblet closed this Apr 4, 2013
@macnibblet macnibblet reopened this Apr 4, 2013
@@ -93,6 +96,15 @@ public function __invoke($name = null, array $params = array(), $options = array
}
}

try {

$params = ArrayUtils::iteratorToArray($params, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this. Check to see if $params is Traversable, and only then do the iteratorToArray() call. This will eliminate the need for the catch and re-throw.

@weierophinney
Copy link
Member

Ideally this should be in the router, not the url() helper -- the reason being that we have TWO url() helpers, and they should be in sync. If we move the $params check to the router's assemble() method instead, we can ensure it works everywhere.

@weierophinney
Copy link
Member

Of course, changing it in assemble() may not be possible, as it would alter typehinting enforced currently by an interface. Since that's the case, you would need to make the change in both url() helpers (controller plugin and view helper).

@macnibblet
Copy link
Contributor Author

Expect an update within the hour need to finish some other stuff on my mind

@macnibblet macnibblet closed this Apr 6, 2013
@macnibblet macnibblet reopened this Apr 6, 2013
);

} else {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all the empty lines here at the beginning of each block?

if (!is_array($params)) {
if (!$params instanceof Traversable) {
throw new Exception\InvalidArgumentException(
'Params is expected to be an array of a Traversable object'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/of/or/

@ghost ghost assigned weierophinney Apr 12, 2013
weierophinney added a commit that referenced this pull request Apr 12, 2013
…port

Allow passing objects to the url helper

Conflicts:
	library/Zend/View/Helper/Url.php
weierophinney added a commit that referenced this pull request Apr 12, 2013
@weierophinney weierophinney merged commit 0c5ed5a into zendframework:develop Apr 12, 2013
weierophinney added a commit to zendframework/zend-view that referenced this pull request May 15, 2015
…eature/url-helper-model-support

Allow passing objects to the url helper

Conflicts:
	library/Zend/View/Helper/Url.php
weierophinney added a commit to zendframework/zend-view that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants