hikozuma
hikozuma

Reputation: 79

Add new controller to existed module in zf3

In Zend framework 3, I tried adding new controller "ArticleController" to a existed module City but failed. I post screen shot, my folder structure and module.config.php. Could you explain what the problem is? Incidentally, it worked when accessing http://0.0.0.0:7000/city

When accessing http://0.0.0.0:7000/article enter image description here enter image description here

Next, module\city\config\module.config.php codes are following:

<?php

namespace City;

use Zend\Router\Http\Segment;

return [
    'router' => [
        'routes' => [
            'city' => [
                'type'    => Segment::class,
                'options' => [
                    'route' => '/city[/:action[/:id]]',
                    'constraints' => [
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ],
                    'defaults' => [
                        'controller' => Controller\CityController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'article' => [
                'type'    => Segment::class,
                'options' => [
                    'route' => '/article[/:action[/:id]]',
                    'constraints' => [
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ],
                    'defaults' => [
                        'controller' => Controller\ArticleController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ],

    'view_manager' => [
        'template_path_stack' => [
            'city' => __DIR__ . '/../view',
        ],
    ],
];  

Upvotes: 0

Views: 757

Answers (1)

Error message is clear. Application doesn't know anything about your controller. Your module config has to have information about controllers under "controllers" key. Checkout zend documentation, you'll see "controllers" key in config file.

Upvotes: 2

Related Questions