草庐IT

php - Zend_Controller_Router_Exception : "xyz" is not specified

coder 2024-04-09 原文

我当前的 Zend Framework 应用程序有问题。

在我的 Bootstrap 中,我注册了这些路由:

protected function _initRouter()
{
    $this->bootstrap("FrontController");
    $frontController = $this->getResource("FrontController");

    $route = new Zend_Controller_Router_Route(
        ":module/:id",
        array(
            "controller" => "index",
            "action" => "index"
            ),
        array("id" => "\d+")
        );
    $frontController->getRouter()->addRoute('shortcutOne', $route);

    $route = new Zend_Controller_Router_Route(
        ":module/:controller/:id",
        array("action" => "index"),
        array("id" => "\d+")
        );
    $frontController->getRouter()->addRoute('shortcutTwo', $route);

    $route = new Zend_Controller_Router_Route(
        ":module/:controller/:action/:id",
        null,
        array("id" => "\d+", "action" => "\w+")
        );
    $frontController->getRouter()->addRoute('shortcutThree', $route);
}

现在我将 Zend_Navigation 添加到我的项目中。我有几个模块,它们在模块 Bootstrap 中注册导航元素:

<?php

class Contact_Bootstrap extends Zend_Application_Module_Bootstrap
{
    protected function _initNavigation()
    {
        $layout = $this->getApplication()->getResource("layout");
        $view = $layout->getView();

        $config = new Zend_Config_Xml(dirname(__FILE__)."/config/navigation.xml", "nav");

        $view->navigation()->addPage($config);
    }
}

当我在浏览器中打开应用程序时,一切正常。这意味着我可以看到导航并单击其链接以查看指定页面。但是当我点击一个使用 :module/:action/:id 路由的页面时,Navigation Helper 会抛出一个 Zend_Controller_Router_Route 异常:

Fatal error: Zend_Controller_Router_Exception: id is not specified in C:\Entwicklung\kt\trunk\src\library\Zend\View\Helper\Navigation\HelperAbstract.php on line 519

你们中有人也遇到过这个错误吗?如果您能帮助我或给我建议,那就太好了。另外,如果您需要有关我的设置等的更多信息,请告诉我。

谢谢!

最佳答案

我自己找到了解决方案。

这个问题是由于 Zend_Navigation 元素的不那么有益的行为引起的。在他们的 getHref() 方法中,他们使用 URL 帮助程序。此帮助器创建导航条目必须链接到的 URL,接收为导航元素(模块、 Controller 、操作等)指定的参数

现在,问题是,如果您像我一样在 Bootstrap 中创建了自定义路由,例如

":module/:controller/:id"

您遇到的问题是,当使用此路由时,URL 帮助程序使用该路由生成导航条目的链接。但是,我没有传递额外的“id”参数,所以我得到了异常。

所以一个解决方案是为每个设置为“默认”的 Zend_Navigation_Page_Mvc 实例“路由”传递一个附加参数。

另一个我还没有尝试过的解决方案是让新的自定义路由将自己重新映射到默认路由上,例如:

":module/:controller/:action/id/$id"

但我不知道你是否有能力使用 Zend Framework 来做到这一点。

关于php - Zend_Controller_Router_Exception : "xyz" is not specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1264834/

有关php - Zend_Controller_Router_Exception : "xyz" is not specified的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby-on-rails - 渲染另一个 Controller 的 View - 2

    我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>

  4. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  5. ruby-on-rails - Rails 应用程序中的 Rails : How are you using application_controller. rb 是新手吗? - 2

    刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr

  6. ruby-on-rails - rails : How to make a form post to another controller action - 2

    我知道您通常应该在Rails中使用新建/创建和编辑/更新之间的链接,但我有一个情况需要其他东西。无论如何我可以实现同样的连接吗?我有一个模型表单,我希望它发布数据(类似于新View如何发布到创建操作)。这是我的表格prohibitedthisjobfrombeingsaved: 最佳答案 使用:url选项。=form_for@job,:url=>company_path,:html=>{:method=>:post/:put} 关于ruby-on-rails-rails:Howtomak

  7. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  8. ruby-on-rails - 相关表上的范围为 "WHERE ... LIKE" - 2

    我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que

  9. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  10. ruby - 安装 Ruby 时遇到问题(无法下载资源 "readline--patch") - 2

    当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub

随机推荐