【问题标题】:ZendFramework XML Routing not workingZendFramework XML 路由不工作
【发布时间】:2025-12-19 01:00:02
【问题描述】:

问题:我看到空白页

我只想在我输入时做

http://localhost --> 转到模块/默认/索引

http://localhost/admin --> 转到模块/管理/索引

index.php 已经不重要了。常用设置

文件夹结构

Bootstrap.php

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initRoutes()
    {
        $front  = $this->getResource('frontcontroller');
        $router = $front->getRouter();
        $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/routes.xml');
        $router->addConfig($config->routes);

    }
}

application.ini

[production]

;Debug output
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0

;Include path
includePaths.library = APPLICATION_PATH "/../library"

;Bootstrap
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"

;NameSpace
appnamespace = "Application"

;Front Controller
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

;Modular suport
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =

;resources.frontController.params.prefixDefaultModule = "1"
;resources.frontController.defaultModule = "default"

;Views
resources.view.encoding = "UTF-8"
resources.view.basePath = APPLICATION_PATH "/views/"
;resources.view.doctype = "XHTML1_STRICT" 
resources.view.doctype = "XHTML1_TRANSITIONAL"

Config.xml

<?xml version="1.0" encoding="UTF-8"?>
<router>
    <routes>
        <some-action>
            <type>Zend_Controller_Router_Route</type>
            <route>:module/:controller</route>
            <defaults>
                <controller>index</controller>
                <action>index</action>
            </defaults>
        </some-action>
    </routes>
</router>

默认控制器

<?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }


}

管理员控制器

<?php

class Admin_IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }


}

.htaccess

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

错误:

致命错误:C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library\Zend\Loader\Autoloader.php 第 380 行的最大执行时间超过 30 秒

【问题讨论】:

  • 请开启异常,并发布错误
  • @ArneRie ,问题末尾附加错误

标签: php zend-framework routing zend-framework-modules


【解决方案1】:

我认为您不需要在这种情况下需要路由器配置?这是 Zend Framework 的标准行为。

我现在不确定,但尝试在您的 IndexController 前加上“Default_”:

class Default_IndexController extends Zend_Controller_Action
{

}

如果这不起作用,请发布您的重写规则。

【讨论】:

  • 不适用于上述更改。在问题末尾添加了重写规则。
【解决方案2】:

为您的路线尝试以下 xml:

<?xml version="1.0" encoding="UTF-8"?>
<router>
    <routes>
        <front>
            <route>/</route>
            <defaults>
                <module>default</module>
                <controller>index</controller>
                <action>index</action>
            </defaults>
        </front>
        <admin>
            <route>/admin</route>
            <defaults>
                <module>admin</module>
                <controller>index</controller>
                <action>index</action>
            </defaults>
        </admin>
    </routes>
</router>

【讨论】: