2012-05-17 51 views
3

在我引導我Zend框架:路線組裝和GET參數

$route = new Zend_Controller_Router_Route(
    ':language/:country/:controller/:action/*', 
    array(
     'language' => 'en', 
     'country' => 'us', 
     'controller' => 'bicycle', 
     'action' => 'index' 
    ), 
    array(
     'language' => '[a-z][a-z]', 
     'country' => '[a-z][a-z]' 
    ) 
); 

某處在我看來,我有

echo $this->url(array('page'=>2)); 
//actually this translated to $route->assemble(array('page' => 2), null, false); 

的問題是,當我有一些GET參數:他們贏了」在鏈接的構建中應該考慮到這一點,而這正是我真正想要的。

實施例: 我訪問該URL(在瀏覽器中)

http://localhost/myproject/en/us/controller/action/?get1=gval1&get2=gval2&get3=gval3 

和組裝的URL是

http://localhost/myproject/en/us/controller/action/page/2 

代替

http://localhost/myproject/en/us/controller/action/page/2/get1/gval1/get2/gval2/get3/gval3/ 

或(我寧願下一個)

http://localhost/myproject/en/us/controller/action/page/2/?get1=gval1&get2=gval2&get3=gval3 

任何想法?

+0

dup:http://stackoverflow.com/questions/2288268/zend-framework-need-to-access-a-get-parameter-from-a-view – ilanco

+0

你實際得到了什麼網址,它有什麼不同從你的期望? – vascowhite

+0

@ilanco,這不是dup,它不是關於如何獲取參數的值,而是關於組裝URL,形成現有的GET參數。 –

回答

2

當然一個解決方案(與Apache)將是在我看來調用這個:

$this->url(array(page=>2)) . ($_SERVER['QUERY_STRING']?$_SERVER['QUERY_STRING']:"") 

,但你不能肯定這將始終包含在$ _SERVER變量。