2012-11-23 27 views
0

比方說,我想了一堆參數傳遞給像網址:CakePHP的URL陣列

http://localhost/my_app/my_controller/index/param1:1/param2:2/param3:3/param4:4 

等等

但我的網址使用Html Helperurl方法建立像這樣:

$this->Html->url(array(
    'controller' => 'my_controller', 
    'action' => 'index', 
    'param1' => 1, 
    'param2' => 2, 
    'param3' => 3, 
    'param4' => 4 
)); 

我試圖建立我的PARAMS成數組這樣並將它傳遞給我的網址,如:

$my_params = array(
    'param1' => 1, 
    'param2' => 2, 
    'param3' => 3, 
    'param4' => 4 
); 

$this->Html->url(array(
    'controller' => 'my_controller', 
    'action' => 'index', 
    $my_params 
)); 

但這並不奏效。任何想法我可以做這個請嗎?

謝謝

回答

4

你打算這樣做是不行的,因爲你只需添加$ my_params到數組時,你應該改爲合併 $ my_params陣列array_merge什麼。

$url = array(
    'controller' => 'my_controller', 
    'action' => 'index' 
); 

$my_params = array(
    'param1' => 1, 
    'param2' => 2, 
    'param3' => 3, 
    'param4' => 4 
); 

$this->Html->url(array_merge($url, $my_params)); 

我希望它能幫助:)