duanhan5230 2015-07-09 21:51
浏览 125
已采纳

ZF2控制台路由和ACL

I've the follow problem with my application.

I make use of ACL, all works fine. I need to setup a Console module for some scraping. I've created te module with controller and route but when I run the command in my console I get an permission error from ACL.

My module.config.php;

return array(
    'router' => array(
        'routes' => array(
        ),
    ),
    'controllers' => array(
        'invokables' => array(
            'Cron\Controller\City'  => 'Application\Controller\CityController',
        ),
    ),
    // Placeholder for console routes
    'console' => array(
        'router' => array(
            'routes' => array(

                'cronroute' => array(
                'options' => array(
                        'route'    => 'getcities',
                        'defaults' => array(
                            'controller' => 'Cron\Controller\City',
                            'action' => 'get'
                        ),
                    ),
                ),

            ),
        ),
    ),
);

My controller;

<?php

namespace Cron\Controller;

use Zend\Mvc\Controller\AbstractActionController;
class CityController extends AbstractActionController
{

    public function getAction()
    {
        echo 'Get cities';
    }
}

And part of my module.acl.roles.php

<?php

return array(

    # Guest
    'guest' => array(

        # Homepage
        'home',

        # Console routes
        'cronroute/getcities', // tried this one
        'getcities', // and this one
    ),

Than the result in the console by the command;

php public_html/index.php getcities



Fatal error: Uncaught exception 'Zend\Permissions\Acl\Exception\InvalidArgumentException' with message 'Resource 'cronroute' not found' in /home/..../domains/..../vendor/zendframework/zendframework/library/Zend/Permissions/Acl/Acl.php:292
  • 写回答

1条回答 默认 最新

  • duanditang2916 2015-07-10 07:01
    关注

    Your ACL resource cronroute/getcities is wrong because it (normally) would check for route getcities as child from cronroute.

    So the solution is to get rid of /getcities behind cronroute in module.acl.roles.php and everything should be fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退