It's the shortest url view helper ever for Zend Framework 2! :-)
Version 1.1.2 Created by Witold Wasiczko
For routing:
user/profile/:id/:slug
Implements interface:
class User implements \ZfSnapUrl\Routable {
/* CODE */
public function getRouteName() {
return 'user/profile';
}
public function getRouteParams() {
return array(
'id' => $this->getId(),
'slug' => $this->getSlug(),
);
}
}Usage in view:
<?= $this->u($this->user) ?>Or you can define multi routes:
class User implements \ZfSnapUrl\Routable {
/* CODE */
public function getRouteName() {
return 'profile';
}
public function getRouteParams() {
return array(
'profile' => array(
'route' => 'user/profile'
'params' => array(
'id' => $this->getId(),
'slug' => $this->getSlug(),
);
),
'edit' => function () {
// You can use closures
return array(
'route' => 'user/super-long-route-name/edit'
'params' => array(
'id' => $this->getId(),
);
),
},
);
}
}And just write in view to print user profile url:
To link user profile (default defined in getRouteName())
<?= $this->u($this->user) ?>
Alias for prev usage
<?= $this->u($this->user, 'profile') ?>
Custom route
<?= $this->u($this->user, 'edit') ?>Without ZfSnapUrl you need to write THIS every single time (!):
<?= $this->url('user/profile', array('id' => $this->user->getId(), 'slug' => $this->user->getSlug())) ?>Via composer
{
"require": {
"snapshotpl/zf-snap-url": "1.*"
}
}composer install --devor
composer updatethen
phpunit --configuration tests/- 1.1.2 Fixes ZF version dependencies in composer.json, small README improvements
- 1.1.1 Travis CI
- 1.1.0 Support for multi routes
- 1.0.0 Stable version with unit test
