Zend 框架自定义路由设置


Zend Framework Custom routes setting

Zend2 
  Sources Files
     Application
        modules 
            default
               controllers 
                   ExampleController.php
               views
                   scripts 
                      form 
                         index.phtml
        library
          square
             form
                Form_Example.php

大家好我正在学习 Zend 框架:初学者指南第 3 章,我在 Square/Form/Form_Example.php 中存在一个form_example类,它基本上有一个表单。

模块/默认/控制器

/示例控制器.php初始化它。但是,我设置了

resources.router.routes.example.route = /example
resources.router.routes.example.defaults.module = default           
resources.router.routes.example.defaults.controller = form
resources.router.routes.example.defaults.action = form 

在应用程序中.ini

当我输入(http://localhost/zend2/public/example)时,它会返回"找不到页面"结果,请帮助我以显示我在Form_Example中创建的表单

谢谢,我真的很感激

我使用

一个单独的文件作为路由,使用这种格式并称之为路由.ini

routes.example.route = /example
routes.example.defaults.module = default           
routes.example.defaults.controller = form
routes.example.defaults.action = form 

在你的引导程序中,你需要这样的东西:

$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();     
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', 'production');      
$router->addConfig($config,'routes');

发现为路由使用不同的文件会使我的主要.ini文件变得不那么复杂,并且更容易理解。