問題描述
我正在嘗試使用 Zend 路由器創(chuàng)建一個(gè)子域,然后為子域下的每個(gè)部分(例如 subdomain.site.com/section/)創(chuàng)建另一個(gè)路由,然后嘗試將其鏈接到子域路由.但我不知道怎么做.我已經(jīng)閱讀了我能找到的所有文檔和所有論壇,但它讓我自己弄清楚了.到目前為止,我的嘗試只會(huì)讓我出現(xiàn)這個(gè)錯(cuò)誤:
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:
可捕獲的致命錯(cuò)誤:參數(shù) 2 傳遞給Zend_Controller_Router_Rewrite::addRoute() 必須實(shí)現(xiàn)接口Zend_Controller_Router_Route_Interface, null 給定, 調(diào)用/var/local/zend/library/Zend/Controller/Router/Rewrite.php 第 155 行并定義在/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
我找不到如何將其與網(wǎng)絡(luò)上任何地方的 INI 文件鏈接的示例.整個(gè)應(yīng)用程序是用 INI 編寫的,用于路由配置,因此我無(wú)法將其切換到基于數(shù)組的配置(或 XML),其中 100% 的互聯(lián)網(wǎng)示例都在其中.
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.
如果我可以用數(shù)組形式來(lái)做,我可以這樣說(shuō):
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)
有人對(duì)如何在 INI 文件中執(zhí)行上述操作有任何想法嗎?
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-signup
和 b2b-anotherroute
.
This will give you the following routes: b2b-signup
, and b2b-anotherroute
.
這里有一些關(guān)于路由鏈接的重要說(shuō)明:
Here's some important notes on route chaining:
將路由鏈接在一起時(shí),外部路由的參數(shù)比內(nèi)部路由的參數(shù)具有更高的優(yōu)先級(jí).因此,如果你在外部和內(nèi)部路由中定義了一個(gè)控制器,則外部路由的控制器將被選中.
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.
父/子鏈?zhǔn)铰酚擅Q總是用破折號(hào)連接!所以,就像上面的例子一樣,b2b.chains.signup
變成了一個(gè)名為 b2b-signup
的路由(你可以用它來(lái)組裝 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).
你可以繼續(xù)鏈接!鏈鏈可以有鏈.
You can keep chaining! Chains of chains can have chains.
鏈?zhǔn)铰酚傻淖蛹?jí)不能使用通配符.請(qǐng)參閱 #ZF-6654.這是博文談?wù)摓槭裁催@可能不是什么大問題.
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.
這篇關(guān)于如何在路由 INI 文件中為 Zend Framework 中的子域編寫路由鏈?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!