如何在Zend Framework中调试路由?

时间:2011-03-21 07:31:45

标签: php zend-framework routing

我的Zend框架路由设置无法正常工作。当我访问“site”时,将根据需要执行application / modules / default / views / script / index / index.phtml下的代码。

但是,当我尝试“site / home”时,我会收到404错误页面。 apache日志显示(文件不存在:/ var / www / site / public / home)。此外,访问http://site/default/index/index会产生相同的结果。 (http://site/index工作正常。)

Zend版本:1.10.8

Apache /etc/apache2/apache2.conf:

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot "/var/www/site/public"

    <Directory /var/www/site/public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

我的/var/www/site/public/.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]

我的/var/www/site/public/index.php

...
/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();

我的application.ini文件:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 0
resources.modules = ""

resources.router.routes.home.route = /home
resources.router.routes.home.defaults.module = default
resources.router.routes.home.defaults.controller = index
resources.router.routes.home.defaults.action = index

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

resources.view[] =

autoloaderNamespaces[] = "Site_"

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

我已经尝试将路由移动到routes.ini并将它们添加到application / Bootstrap.php中,如下所示:

   $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', 'production');
   $router = new Zend_Controller_Router_Rewrite();
   $router->addConfig($config, 'routes');

  $r = new Zend_Controller_Router_Route(
      'home/',
      array(
          'controller' => 'index',
          'action'     => 'index'
      )
  );
  $router->addRoute('home', $r);

然而,它没有帮助。我花了一整天的时间浏览手册,书籍和网络论坛,试图找到问题无济于事。 (我一直关注Vikram Vaswani的“Zend Framework”。)

2 个答案:

答案 0 :(得分:1)

我的虚拟目录:

<Directory /var/www/site/public/>
    Options Indexes FollowSymlinks

    php_admin_flag engine on
    php_admin_flag safe_mode off
    php_admin_value open_basedir none
</Directory>

答案 1 :(得分:1)

试试这个apache虚拟主机配置:

<VirtualHost *:80>
    DocumentRoot "/var/www/site/public"
    ServerName mysite

    <Directory "/var/www/site/public">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>