Zend 1.12:向我的控制器发送路由请求的问题

时间:2014-12-26 22:52:06

标签: php zend-framework

我是Zend框架的新手,并且最近努力将请求路由到我的控制器,这不是与示例项目一起创建的IndexController。 事实上,我创建了一个SpotController(带有索引,添加,删除,更新方法和视图文件),我似乎无法访问索引方法,因为我得到 500内部服务器错误

以下是我在IndexController视图中链接到我的控制器的索引方法:

<p>
    <a href="<?php echo $this->url(array('controller'=>'spot','action'=>'index'),'default'); ?>">See spot</a>
</p>

这是我的 routes.ini 文件(在APPLICATION_PATH / config中):

routes.routename.route = "spot"
routes.routename.defaults.module = default
routes.routename.defaults.controller = spot
routes.routename.defaults.action = index

这是我的 Boostrap.php _initRouter()方法:

protected function _initRouter(){
        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini');
        $front = Zend_Controller_Front::getInstance();
        $router = $front->getRouter();
        $router->addConfig($config,'routes');
        $front->setRouter($router);
        return $router;
    }

我想有些事情我做错了,我发现zend的文档在这个主题上非常不准确。 只是为了让你知道,我可以正常访问我的IndexController。

提前致谢, 干杯!

2 个答案:

答案 0 :(得分:0)

首先,我建议你打开php错误显示,因为你正处于开发阶段,将以下内容放入application.ini文件中

phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

500错误类型是内部服务器错误,如果您使用的是Apache服务器。您需要检查.htaccess文件,这些文件可能来自不在Apache中启用的mod_rewrite module不同的天使,或者在.htaccess中需要RewriteBase /规则(在共享主机上) 虚拟主机配置中缺少AllowOverride All

您的public/.htaccess文件应如下所示

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

希望可能有所帮助

答案 1 :(得分:0)

我在.htaccess中删除了两条规则,使其看起来与您的推荐完全一致,一切正常:)非常感谢您的帮助!

以下是我删除的两行,如果它可以帮助任何人:

RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::$
RewriteRule ^(.*)$ - [E=BASE:%1]
相关问题