0
votes

I create the controller and the view but I'm getting this error:

Zend\Mvc\Controller\ControllerManager::createFromInvokable: failed retrieving "newprojectcontrollernewproject(alias: Newproject\Controller\Newproject)" via invokable class "Newproject\Controller\new_controller"; class does not exist

Module.php

namespace Newproject;

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

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }
}

module.config.php

return array(
    'controllers' => array(
        'invokables' => array('Newproject\Controller\Newproject' => 'Newproject\Controller\new_controller'),
    ),
    'router' => array(
        'routes' => array(
            'newproject' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/newproject[/:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id' => '[0-9]+'),
                        'defaults' => array(
                            'controller' => 'Newproject\Controller\Newproject',
                            'action' => 'index'
                        ),
                    )
                )
            )
        ),
        'view_manager' => array('template_path_stack' => array('newproject' => __DIR__.'/../view'),
    ),
);

Controller class new_controller.php

namespace Newproject\Controller;

use Zend\Mvc\Controller\AbstractActionController; 

class new_controller extends AbstractActionController 
{
    public function indexAction()
    {
    } 
}
1
new_controller is not a valid name. Change it to NewControllerStanimir Dimitrov
What's the full path (including filename) to your new controller file?Tim Fountain

1 Answers

0
votes

As detailed in http://framework.zend.com/manual/current/en/user-guide/routing-and-controllers.html, controllers must begin with a capital letter. It's also good practice to stick to standard naming conventions, which means using NewController instead of the very, very old school underscore class naming convention (new_controller).

In case that doesn't work, take a look at config/application.config.php. If configuration file caching is enabled, the relevant files will need to be deleted before this will work.

Based on what you've posted, I recommend the following changes:

<?php

return array(
    'controllers' => array(
        'invokables' => array(
            'NewProject\Controller\New' => 'NewProject\Controller\NewController'
        ),
    ),
    'router' => array(
        'routes' => array(
            'new_project' => array(
                'type' => 'Segment',
                'options' => array(
                    'route' => '/new-project[/:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id' => '[0-9]+',
                    ),
                    'defaults' => array(
                        '__NAMESPACE__' => 'NewProject\Controller',
                        'controller' => 'New',
                        'action' => 'index',
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'new-project' => __DIR__.'/../view'
        ),
    ),
);

And the controller...

<?php

namespace NewProject\Controller;

use Zend\Mvc\Controller\AbstractActionController; 

class NewController extends AbstractActionController 
{
    public function indexAction()
    {
    } 
}