我正在尝试在 zend 中进行简单的路由以用于教育目的。在我说什么之前,我下载了 3 个 zend 教程,4 个 pdf,但我仍然坚持最简单的任务。我什至阅读了官方文档,但仍然无法理解它是如何工作的。
我正在尝试创建简单的引导程序主页关于和联系页面,但发现路由的工作方式没有运气。我尝试配置模块/模块名称/模块.config.php添加自定义路由但没有运气。我是否需要为每个静态页面(如"关于"和"联系人")设置单独的模块,还是为每个页面设置一个模块和单独的控制器?以及如何处理路由 www.example.com/about 我得到的只是这个,它不起作用
这是我的模块配置.php
namespace Application;
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'ZendMvcRouterHttpLiteral',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'ApplicationControllerIndex',
'action' => 'index',
),
),
),
'about' => array(
'type' => 'ZendMvcRouterHttpLiteral',
'options' => array(
'route' => '/about',
'defaults' => array(
'controller' => 'ApplicationControllerAbout',
'action' => 'index',
),
),
),
在 src/Application/Controler 中,我有 IndexControler.php 和 AboutController.php以及在view/application/index index.phtml和关于PHTML中。
关于控制器
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http:/o/github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace ApplicationController;
use ZendMvcControllerAbstractActionController;
use ZendViewModelViewModel;
class AboutController extends AbstractActionController
{
public function indexAction()
{
return new ViewModel();
}
}
我认为您缺少可调用项。在上面的 module.config.php 文件中,您还应该添加以下行,以便您的代码开始工作。
在 module.config 中添加下面的代码.php
'controllers' => array(
'invokables' => array(
'ApplcationControllerIndex' => 'ApplicationControllerIndexController',
'ApplcationControllerAbout' => 'ApplicationControllerAboutController',
'ApplcationControllerContact' => 'ApplicationControllerContactController',
),
),
此链接将更好地了解缺少的内容。http://framework.zend.com/manual/current/en/user-guide/routing-and-controllers.html
祝你好运