Blog module Zend 3 tutorial

For programming and general questions on Zend Framework

Blog module Zend 3 tutorial

Postby nach4528 on Mon Oct 23, 2017 9:01 am

Hi,

I'm following .../tutorials/in-depth-guide/first-module/ and I get the following error:

A 404 error occurred
Page not found.
The requested controller could not be mapped to an existing controller class.

Controller:
ListController (resolves to invalid controller class or alias: ListController)
No Exception available

These are the files:

composer.json
Code: Select all
...
"autoload": {
        "psr-4": {
            "Application\\": "module/Application/src/",
            "Album\\": "module/Album/src/",
            "Blog\\": "module/Blog/src/"
        }
    },
...


I run the following command: composer dump-autoload


config/modules.config.php

Code: Select all
<?php
/**
* @link      zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc.
* @license  .../license/new-bsd New BSD License
*/

/**
* List of enabled modules for this application.
*
* This should be an array of module namespaces used in the application.
*/
return [
    'Zend\Paginator',
    'Zend\Navigation',
    'Zend\ServiceManager\Di',
    'Zend\Session',
    'Zend\Mvc\Plugin\Prg',
    'Zend\Mvc\Plugin\Identity',
    'Zend\Mvc\Plugin\FlashMessenger',
    'Zend\Mvc\Plugin\FilePrg',
    'Zend\Mvc\I18n',
    'Zend\Mvc\Console',
    'Zend\Log',
    'Zend\Form',
    'Zend\Db',
    'Zend\Cache',
    'Zend\Router',
    'Zend\Validator',
    'ZendDeveloperTools',
    'Application',
    'Album',
    'Blog'
];




module/Blog/src/Module.php

Code: Select all
<?php

namespace Blog;

class Module

{     
    public function getConfig()
    {
        return include __DIR__ . '/../config/module.config.php';
    }
   
}



module/Blog/config/module.config.php

Code: Select all
<?php

use Zend\Router\Http\Literal;
use Zend\ServiceManager\Factory\InvokableFactory;

return [
    'controllers' => [
        'factories' => [
            Controller\ListController::class => InvokableFactory::class,
        ],
    ],

    // This lines opens the configuration for the RouteManager
    'router' => [
        // Open configuration for all possible routes
        'routes' => [
            // Define a new route called "blog"
            'blog' => [
                // Define a "literal" route type:
                'type' => Literal::class,
                // Configure the route itself
                'options' => [
                    // Listen to "/blog" as uri:
                    'route' => '/blog',
                    // Define default controller and action to be called when
                    // this route is matched
                    'defaults' => [
                        'controller' => ListController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ],
    'view_manager' => [
        'template_path_stack' => [
            __DIR__ . '/../view',
        ],
    ],
];


In the tutorial, the line default controller for Blog module is 'controller' => Controller\ListController::class, but with this line I get the following error:

) Fatal error: Class 'Controller\ListController' not found in ...\skeleton-app\vendor\zendframework\zend-servicemanager\src\Factory\InvokableFactory.php on line 30
Call Stack
# Time Memory Function Location
1 0.0019 138248 {main}( ) ...\index.php:0
2 0.4326 5040240 Zend\Mvc\Application->run( ) ...\index.php:40
3 0.4402 5078992 Zend\EventManager\EventManager->triggerEventUntil( ) ...\Application.php:332
4 0.4402 5078992 Zend\EventManager\EventManager->triggerListeners( ) ...\EventManager.php:179
5 0.4410 5082320 Zend\Mvc\DispatchListener->onDispatch( ) ...\EventManager.php:322
6 0.4411 5082464 Zend\ServiceManager\AbstractPluginManager->get( ) ...\DispatchListener.php:102
7 0.4411 5082496 Zend\ServiceManager\ServiceManager->get( ) ...\AbstractPluginManager.php:141
8 0.4411 5082496 Zend\ServiceManager\ServiceManager->doCreate( ) ...\ServiceManager.php:200
9 0.4411 5082584 Zend\ServiceManager\Factory\InvokableFactory->__invoke( ) ...\ServiceManager.php:758

So i changed it to:

'controller' => ListController::class,


As I did with the AlbumController (.../tutorials/getting-started/overview/) and It worked with Album module but not with Blog module...

module/Blog/src/Controller/ListController.php

Code: Select all
<?php

namespace Blog\Controller;

use Zend\Mvc\Controller\AbstractActionController;

class ListController extends AbstractActionController
{
}


module/Blog/view/blog/list/index.phtml

Code: Select all
<h1>Blog\ListController::indexAction()</h1>


Could you help me please?

thank you in advance,
Ignacio Martínez
nach4528
 
Posts: 5
Joined: Wed Oct 18, 2017 11:39 am

Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 5 guests