[英]Zend Framework 2, “resolves to invalid controller class or alias” Blog module from the tutorial
i have been following the steps of the Blog tutorial from Zend mainpage( https://framework.zend.com/manual/2.4/en/in-depth-guide/first-module.html ) but i got stuck on this error: "resolves to invalid controller class or alias". 我一直在关注Zend主页( https://framework.zend.com/manual/2.4/en/in-depth-guide/first-module.html )的博客教程的步骤,但我遇到了这个错误: “解析为无效的控制器类或别名”。
heres my module.config.php: 继承我的module.config.php:
<?php
// Filename: /module/Blog/config/module.config.php
return array(
// This lines opens the configuration for the RouteManager
'router' => array(
// Open configuration for all possible routes
'routes' => array(
// Define a new route called "post"
'post' => array(
'type' => 'literal',
// Configure the route itself
'options' => array(
// Listen to "/blog" as uri
'route' => '/blog',
'defaults' => array(
'controller' => 'Blog\Controller\List',
'action' => 'index',
)
)
)
)
)
);
return array(
'controllers' => array(
'invokables' => array(
'Blog\Controller\List' => 'Blog\Controller\ListController'
)
),
'router' => array( /** Route Configuration */ )
);
return array(
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
'controllers' => array( /** Controller Configuration */),
'router' => array( /** Route Configuration */ )
);
heres my Module.php : 继承我的Module.php:
<?php
// Filename: /module/Blog/Module.php
namespace Blog;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
class Module implements
AutoloaderProviderInterface,
ConfigProviderInterface
{
/**
* Return an array for passing to Zend\Loader\AutoloaderFactory.
*
* @return array
*/
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
)
)
);
}
/**
* Returns configuration to merge with application configuration
*
* @return array|\Traversable
*/
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}
my ListController.php: 我的ListController.php:
<?php
// Filename: /module/Blog/src/Blog/Controller/ListController.php
namespace Blog\Controller;
use Zend\Mvc\Controller\AbstractActionController;
class ListController extends AbstractActionController
{
}
it seems fully equal to the guide code, but i might have miss something. 它似乎完全等于指南代码,但我可能会错过一些东西。 The blog module was declared on the application config too.
博客模块也在应用程序配置中声明。 Help is apreciated :s thank you for your time
帮助是apreciated:谢谢你的时间
Problem is in your module.config.php
file. 问题出在你的
module.config.php
文件中。 You have there 3 times return
statement, so only first part (router configuration) of configuration file is returned, rest is skipped. 你有3次
return
语句,所以只返回配置文件的第一部分(路由器配置),跳过rest。
Your configuration file should looks like this: 您的配置文件应如下所示:
// Filename: /module/Blog/config/module.config.php
return array(
// This lines opens the configuration for the RouteManager
'router' => array(
// Open configuration for all possible routes
'routes' => array(
// Define a new route called "post"
'post' => array(
'type' => 'literal',
// Configure the route itself
'options' => array(
// Listen to "/blog" as uri
'route' => '/blog',
'defaults' => array(
'controller' => 'Blog\Controller\List',
'action' => 'index',
)
)
)
)
),
'controllers' => array(
'invokables' => array(
'Blog\Controller\List' => 'Blog\Controller\ListController'
)
),
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.