zend framework 2 一个主模块中的嵌套模块结构
zend framework 2 nested module structure in one main module
我正在尝试使用 zend framework 2 创建一个应用程序。使用的结构如下。未找到获取错误 class。尝试在名为 album 的主模块中创建嵌套子模块登录。
我有以下结构:
Album
- src
- Album
- Controller
- AlbumController.php
- Form
- AlbumForm.php
- Model
- Login
- Controller
- LoginController.php
- Form
- LoginForm.php
- Model
出现以下错误:
Zend\Mvc\Controller\ControllerManager::createFromInvokable: failed retrieving "logincontrollerlogin(alias: Login\Controller\Login)" via invokable class "Login\Controller\LoginController"; class does not exist
路由如下:
return array(
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
'Login\Controller\Login' => 'Login\Controller\LoginController',
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'login' => array(
'type' => 'segment',
'options' => array(
'route' => '/login',
'defaults' => array(
'controller' => 'Login\Controller\Login',
'action' => 'index',
),
),
),
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
'login' => __DIR__ . '/../view',
),
), );
你能帮我解决上面的错误吗:
在 Module.php 中自动加载:
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
您的自动加载器可能找不到您的控制器,因为它位于不同的命名空间下。尝试指定登录命名空间,看看是否有帮助。
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
'Login' => __DIR__ . '/src/Login',
),
),
我正在尝试使用 zend framework 2 创建一个应用程序。使用的结构如下。未找到获取错误 class。尝试在名为 album 的主模块中创建嵌套子模块登录。
我有以下结构:
Album
- src
- Album
- Controller
- AlbumController.php
- Form
- AlbumForm.php
- Model
- Login
- Controller
- LoginController.php
- Form
- LoginForm.php
- Model
出现以下错误:
Zend\Mvc\Controller\ControllerManager::createFromInvokable: failed retrieving "logincontrollerlogin(alias: Login\Controller\Login)" via invokable class "Login\Controller\LoginController"; class does not exist
路由如下:
return array(
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
'Login\Controller\Login' => 'Login\Controller\LoginController',
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'login' => array(
'type' => 'segment',
'options' => array(
'route' => '/login',
'defaults' => array(
'controller' => 'Login\Controller\Login',
'action' => 'index',
),
),
),
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
'login' => __DIR__ . '/../view',
),
), );
你能帮我解决上面的错误吗:
在 Module.php 中自动加载:
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
您的自动加载器可能找不到您的控制器,因为它位于不同的命名空间下。尝试指定登录命名空间,看看是否有帮助。
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
'Login' => __DIR__ . '/src/Login',
),
),