2012-11-23 38 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)); 

我希望它能帮助:)