Problem with Module.php in Debug module?

Home Forums Learn ZF2 Problem with Module.php in Debug module?

This topic contains 5 replies, has 5 voices, and was last updated by  brad147fr@yahoo.fr 3 years ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #247

    Hi.

    I started working through Learn ZF2 on Google Play and at the end of the Debug module chapter could not get the Application to run. A bit of troubleshooting showed that I was getting the following:

    PHP Fatal error: Class Debug\\Module contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Zend\\ModuleManager\\Feature\\AutoloaderProviderInterface::getAutoloaderConfig) in <APP_PATH>/learnzf2/module/Debug/Module.php on line 24

    The complete contents were:

    <?php
    
    namespace Debug;
    
    use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
    use Zend\Mvc\ModuleRouteListener;
    use Zend\ModuleManager\ModuleManager;
    use Zend\EventManager\Event;
    
    class Module implements AutoloaderProviderInterface
    {
        public function init(ModuleManager $moduleManager)
        {
            $eventManager = $moduleManager->getEventManager();
            $eventManager->attach('loadModules.post', array($this, loadedModulesInfo'));
        }
        
        public function loadedModulesInfo(Event $event)
        {
            $moduleManager = $event->getTarget();
            $loadedModules = $moduleManager->getLoadedModules();
            error_log(var_export($loadedModules, true));
        }
    }

    I added

    ` public function getAutoloaderConfig()
    {
    //test
    }`

    and the module now works.

    Some helpful system info:

    php –version
    PHP 5.3.10-1ubuntu3.9 with Suhosin-Patch (cli) (built: Dec 12 2013 04:27:25)
    Copyright (c) 1997-2012 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

    I’m not sure if I missed something, but it didn’t seem as though I had.

    Thank you!

    #248

    fdkhadra@gmail.com
    Participant

    Hello,
    I just recieve the book yesterday. I got the same issue. Waiting for feedback too. Btw sorry if i do some mistake, english it’s not my mother tongue.
    Hope we understand where the problem is coming from,
    Thank you !

    #250

    zimzum74@gmail.com
    Participant

    Hi,

    There is a part, which I don’t understand: when the book shows 3 ways to create the Debug Module (manually, with ZFtool, and with Zend Studio).
    I tried all of them as written, but they give 3 different result: they differ in the directory structure, and in the contents of the files too.
    (E.g. with ZFtool the module.config.php returns just an empty array, the Controller directory is empty, etc.)

    The Zend Studio result is more similar to the manual creation, but there are several differences in the contents of the files.
    So which one is the good one?
    (By the way, this Debug Module is missing from the online
    repository: https://github.com/slaff/learnzf2 – so I can’t check there.)

    Thank you, P M

    #260

    Slavey Karadzhov
    Participant

    > class Module implements AutoloaderProviderInterface
    The class does not have to implement the AutoloaderProviderInterface. Which tool did you use to create the class? Was it created with Zend Studio, manually from you or you created it using zftool.phar?

    #261

    Slavey Karadzhov
    Participant

    > (By the way, this Debug Module is missing from the online
    repository: https://github.com/slaff/learnzf2 – so I can’t check there.)

    The Debug module is there. You just have to rewind the repository to the correct location. You can try the following git command:
    git checkout ‘ch-debug-module’

    At the end of the book we show how the debug module can be distributed as a separate package and that why in the final code (the one that you have when you just clone the repository) it does not exist.

    If possible follow closely the git commands given in the book.

    #337

    brad147fr@yahoo.fr
    Participant

    Took me sometime also to make it work. Here is what I did (stupidly simple) using ZendFramework-2.3.1 on ZendServer-6.3.0-php-5.5.7 using ZendStudio-10.6.0

    Automatic Module Creation with Zend Studio : just use the wizard like explained in paragraphe 9.3

    Do not change anything in the Module.php (i.e. bypass paragraph 9.4)

    Just go to your_app/module/debug/config/module.config.php and change
    ‘route’ => ‘/index’
    -INTO-
    ‘route’ => ‘/debug’
    under line 13 where it’s written // Change this to something specific to your module so module.config.php now looks like this

    <?php
    return array(
        'controllers' => array(
            'invokables' => array(
                'Debug\Controller\Index' => 'Debug\Controller\IndexController',
            ),
        ),
        'router' => array(
            'routes' => array(
                'debug' => array(
                    'type'    => 'Literal',
                    'options' => array(
                        // Change this to something specific to your module
                        'route'    => '/debug',
                        'defaults' => array(
                            // Change this value to reflect the namespace in which
                            // the controllers for your module are found
                            '__NAMESPACE__' => 'Debug\Controller',
                            'controller'    => 'Index',
                            'action'        => 'index',
                        ),
                    ),
                    'may_terminate' => true,
                    'child_routes' => array(
                        // This route is a sane default when developing a module;
                        // as you solidify the routes for your module, however,
                        // you may want to remove it and replace it with more
                        // specific routes.
                        'default' => array(
                            'type'    => 'Segment',
                            'options' => array(
                                'route'    => '/[:controller[/:action]]',
                                'constraints' => array(
                                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                    'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                                ),
                                'defaults' => array(
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),
        'view_manager' => array(
            'template_path_stack' => array(
                'Debug' => __DIR__ . '/../view',
            ),
        ),
    );

    and Module.php looks like this

    <?php
    /**
     * Zend Framework (http://framework.zend.com/)
     *
     * @link      http://github.com/zendframework/Debug for the canonical source repository
     * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
     * @license   http://framework.zend.com/license/new-bsd New BSD License
     */
    
    namespace Debug;
    
    use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
    use Zend\Mvc\ModuleRouteListener;
    use Zend\Mvc\MvcEvent;
    use Zend\ModuleManager\ModuleManager;
    
    class Module implements AutoloaderProviderInterface
    {
        public function getAutoloaderConfig()
        {
            return array(
                'Zend\Loader\ClassMapAutoloader' => array(
                    __DIR__ . '/autoload_classmap.php',
                ),
                'Zend\Loader\StandardAutoloader' => array(
                    'namespaces' => array(
    		    // if we're in a namespace deeper than one level we need to fix the \ in the path
                        __NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/' , __NAMESPACE__),
                    ),
                ),
            );
        }
    
        public function getConfig()
        {
            return include __DIR__ . '/config/module.config.php';
        }
    
        public function onBootstrap(MvcEvent $e)
        {
            // You may not need to do this if you're doing it elsewhere in your
            // application
            $eventManager        = $e->getApplication()->getEventManager();
            $moduleRouteListener = new ModuleRouteListener();
            $moduleRouteListener->attach($eventManager);
        }
    }
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.