开发者

How to debug routing in Zend Framework?

My Zend framework routing setup is not working as desired. When I access "site", the code under application/modules/default/views/script/index/index.phtml is executed, as desired.

However, when I try "site/home", I get a 404 error page. The apache log shows ( File does not exist: /var/www/site/public/home). In addition, accessing http://site/default/index/index produces the same result. (http://site/index works fine.)

Zend version: 1.10.8

Apache /etc/apache2/apache2.conf:

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

    <Directo开发者_JS百科ry /var/www/site/public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

My /var/www/site/public/.htaccess file

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]

My /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();

My application.ini file:

[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

I have tried moving routes into routes.ini and adding them in application/Bootstrap.php as follows:

   $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);

However, it did not help. I spent the entire day going through the manuals, books, and web forums trying to find the problem to no avail. (I have been following "Zend Framework" by Vikram Vaswani.)


My Vhost Directory:

<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>


Try this apache virtual host config:

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜