正如我在zf2 2.3文档之后所做的一切正常,直到我尝试创建一个名为usercontroller的新控制器并且在设置之后我将这个错误包括在内:
Fatal error: Class 'Album\Controller\UserController' not found in /var/www/html/sites/xxxxx/vendor/zendframework/zendframework/library/Zend/ServiceManager/AbstractPluginManager.php on line 171
我已将其包含在invokables和路由中:
#invokeables
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
'Album\Controller\User' => 'Album\Controller\UserController',
),
#added user route along with album route
'user' => array(
'type' => 'segment',
'options' => array(
'route' => '/user[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\User',
'action' => 'index',
),
),
),
#UserController
namespace User\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class UserController extends AbstractActionController
{
public function indexAction()
{
}
}
#Module.php
namespace Album;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
class Module implements AutoloaderProviderInterface, ConfigProviderInterface
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}
答案 0 :(得分:0)
在 UserController请替换您的行
namespace User\Controller;
<强>与强>
namespace Album\Controller;