如何在路由INI文件中的Zend Framework中为子域编写路由链? [英] How do I write Routing Chains for a Subdomain in Zend Framework in a routing INI file?

查看:82
本文介绍了如何在路由INI文件中的Zend Framework中为子域编写路由链?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Zend Router创建一个子域,然后为该子域下的每个部分创建一个子域,例如subdomain.site.com/section/.我正在创建另一个路由,然后尝试将其链接到该子域路由.但我不知道怎么做我已经阅读了所有可以找到的文档和所有论坛,但是这使我自己弄清楚了.到目前为止,我的尝试仅使我遇到此错误:

I am trying to create a subdomain using the Zend Router, and then for each section under a subdomain, such as subdomain.site.com/section/ I am creating another route and then trying to chain it to the subdomain route. but I don't know how. I have read all the documentation I could find and all the forums, but it leads me to figure it out on my own. So far, my attempts just get me this error:

可捕获的致命错误:参数2传递给 Zend_Controller_Router_Rewrite :: addRoute()必须实现接口 Zend_Controller_Router_Route_Interface,给定null,在中调用 第155行的/var/local/zend/library/Zend/Controller/Router/Rewrite.php 并在 /var/local/zend/library/Zend/Controller/Router/Rewrite.php,第93行

Catchable fatal error: Argument 2 passed to Zend_Controller_Router_Rewrite::addRoute() must implement interface Zend_Controller_Router_Route_Interface, null given, called in /var/local/zend/library/Zend/Controller/Router/Rewrite.php on line 155 and defined in /var/local/zend/library/Zend/Controller/Router/Rewrite.php on line 93

具有以下代码:

routes.b2b.type = "Zend_Controller_Router_Route_Hostname"
routes.b2b.route = "sales.sitename.com"
routes.b2b.defaults.module = b2b
routes.b2b.defaults.controller = index
routes.b2b.defaults.action = index

routes.b2b_signup.type = "Zend_Controller_Router_Route_Static"
routes.b2b_signup.route = "/signup"
routes.b2b_signup.defaults.controller = "index"
routes.b2b_signup.defaults.action   = "signup"

routes.b2b_login.type = "Zend_Controller_Router_Route_Chain"
routes.b2b_login.chain = b2b_signup

我找不到在网络上任何地方如何将其与INI文件链接起来的示例.整个应用程序都是用INI编写的,用于路由配置,因此我无法将其切换到基于数组的配置(或XML),Internet上的100%的示例都在其中.

I cannot find an example of how to do chaining this with an INI file anywhere on the net. The entire application is written in an INI for the routing config, so I can't switch it over to an array based config (or XML for that matter), in which 100% of the examples on the internet are in.

如果我能以数组形式做到这一点,我可以这样说:

If I could do it in array form, I could just say this:

$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
    'sales.sitename.com',
    array(
        'controller' => 'index',
        'module'     => 'b2b',
        'action'     => 'index'
    )
);

$hostnameRoute = new Zend_Controller_Router_Route_Static(
    '/signup',
    array(
        'controller' => 'index',
        'module'     => 'b2b',
        'action'     => 'signup'
    )
);
    $chainedRoute = new Zend_Controller_Router_Route_Chain();
    $chainedRoute->chain($b2b_signup)

有人对INI文件中的上述操作有任何想法吗?

Does anyone have any ideas on how to do the above in an INI file?

推荐答案

基本上,这就是您想要的INI格式:

Here's basically what you want, in INI format:

routes.b2b.type = "Zend_Controller_Router_Route_Hostname"
routes.b2b.route = "sales.sitename.com"
; you could specify a default module (or anything) to use for the whole 
; route chain here, like so: 
; routes.b2b.defaults.module = "default"

routes.b2b.chains.signup.type = "Zend_Controller_Router_Route_Static"
routes.b2b.chains.signup.route = "/signup"
routes.b2b.chains.signup.defaults.controller = "index"
routes.b2b.chains.signup.defaults.action = "signup"

routes.b2b.chains.anotherroute.route = "/something/:foo" ; etc, etc.
routes.b2b.chains.anotherroute.defaults.action = "foo"
routes.b2b.chains.anotherroute.defaults.controller = "index"
routes.b2b.chains.anotherroute.defaults.foo = "bar"
routes.b2b.chains.anotherroute.reqs.foo = '[a-z]+'

这将为您提供以下路线:b2b-signupb2b-anotherroute.

This will give you the following routes: b2b-signup, and b2b-anotherroute.

以下是关于路线链接的一些重要说明:

Here's some important notes on route chaining:

将路线链接在一起时,外部路线的参数比内部路线的参数具有更高的优先级.因此,如果在外部路径和内部路径中定义控制器,则将选择外部路径的控制器.

When chaining routes together, the parameters of the outer route have a higher priority than the parameters of the inner route. Thus if you define a controller in the outer and in the inner route, the controller of the outer route will be selected.

父/子链接的路线名称始终以短划线连接!因此,像上面的示例一样,b2b.chains.signup成为名为b2b-signup的路由(可用于URL组装等).

Parent / child chained route names are always concatenated with a dash! So, like in the example above, b2b.chains.signup becomes a route named b2b-signup (which you can use for URL assembly, etc).

您可以继续链接!链的链可以有链.

You can keep chaining! Chains of chains can have chains.

链接路径的子代不能与通配符一起使用.参见#ZF-6654 .这是博客文章,谈论为什么这可能没什么大不了的.

Children of chained routes do not work with wildcards. See #ZF-6654. Here's blog post that talks about why that may not be a big deal.

这篇关于如何在路由INI文件中的Zend Framework中为子域编写路由链?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆