Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZF2: Get url parameters in controller

I have experienced Zend Framework 1 and I've build some apps with that framework.

Now, I'm experimenting Zend Framework 2, but I'm stuck on the url parameters. I've setup my routing like this:

// Setup for router and routes 'Zend\Mvc\Router\RouteStack' => array(     'parameters' => array(         'routes' => array(             'default' => array(                 'type'    => 'Zend\Mvc\Router\Http\Segment',                 'options' => array(                     'route'    => '/[:slug]',                     'constraints' => array(                     'slug' => '[a-zA-Z][a-zA-Z0-9_\/-]*'                     ),                 'defaults' => array(                     'controller' => 'Htmlsite\Controller\BootController',                     'action'     => 'index',                     'slug' => 'home'                     ),                 ),             ),         'home' => array(             'type' => 'Zend\Mvc\Router\Http\Literal',             'options' => array(                 'route'    => '/',                 'defaults' => array(                     'controller' => 'Htmlsite\Controller\BootController',                     'action'     => 'index',                     ),                 ),             ),         ),     ), ), 

As you can see, I've tried to make a variable slug. How can I access this variable?

like image 931
koenHuybrechts Avatar asked Apr 05 '12 08:04

koenHuybrechts


1 Answers

Or simply:

$slug= $this->params('slug'); 
like image 173
Al-Punk Avatar answered Oct 11 '22 05:10

Al-Punk