2014-06-27 59 views
0

我遵循本教程:http://ivangospodinow.com/zend-framework-2-acl-setup-in-5-minutes-tutorial/ 但是,我想通過自定義URL授予權限,所以我在代碼中進行了一些更改。通過Zend Framework中的URL授予ACL許可2

module.acl.roles.php

return array(
    'guest'=> array(
     '/home.html', 
     '/login.html', 
     '/register.html' 
    ), 
    'admin'=> array(
     '/user/add.html', 
     '/user/edit.html', 
     '/user/list.html', 
    ), 
); 

module.config.php

return array(
    'router' => array(
     'routes' => array(
      '/home.html' => array(
       'type' => 'Zend\Mvc\Router\Http\Literal', 
       'options' => array(
        'route' => '/', 
        'defaults' => array(
         'controller' => 'Application\Controller\Index', 
         'action' => 'index', 
        ), 
       ), 
      ), 
      '/user/add.html' => array(
       'type' => 'Zend\Mvc\Router\Http\Regex', 
       'options' => array(
        'regex' => '/user/add.html', 
        'defaults' => array(
         'controller' => 'Application\Controller\User', 
         'action' => 'add', 
         'format' => 'html', 
        ), 
        'spec' => '/user/add.%format%', 
       ), 
      ), 
      ... 
     ), 
    ), 
); 

但我收到此錯誤:Route with name "" not found。請給我一些建議和解決方案,授予URL的許可

謝謝!

+2

我建議你看看https://github.com/bjyoungblood/BjyAuthorize相反,即路線守衛 – Xerkus

回答

0

我真的很推薦BjyAuthorize模塊(https://packagist.org/packages/bjyoungblood/bjy-authorize)。

但是,如果你真的想通過yourselft來做到這一點,你需要添加一個監聽器到\Zend\Mvc\MvcEvent::EVENT_ROUTE

您可以將您的收聽與

$events->attach(MvcEvent::EVENT_ROUTE, array($this, 'myOnRoute'), -1000); 

,並在您myOnRoute方法可以處理路線

public function myOnRoute(MvcEvent $event) { 
    $match  = $event->getRouteMatch(); 
    $routeName = $match->getMatchedRouteName(); 
    // do stuff here (compare to config or whatever) 
}