3
我一直在關注Zend主頁(https://framework.zend.com/manual/2.4/en/in-depth-guide/first-module.html)的博客教程的步驟,但是我陷入了這個錯誤:「解析爲無效的控制器類別或別名「。Zend Framework 2「解決無效的控制器類別或別名」本教程的博客模塊
繼承人我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 */)
);
繼承人我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';
}
}
我ListController.php:
<?php
// Filename: /module/Blog/src/Blog/Controller/ListController.php
namespace Blog\Controller;
use Zend\Mvc\Controller\AbstractActionController;
class ListController extends AbstractActionController
{
}
似乎完全等於指導代碼,但我可能會錯過一些東西。博客模塊也在應用程序配置中聲明。 幫助是apreciated:s謝謝你的時間
太謝謝你了! :)它完美的作品。 –
我很高興,我可以幫你:) – SzymonM
@BrunoMonteiro如果它有助於解決你的問題,請接受答案。 – Wilt