2015-10-20 78 views
1

我正在Cakephp項目上工作,我有一個控制器,它提出了一些算法並將信息保存到數組中。我需要在同一個控制器上調用另一個方法,並將該數組作爲參數發送。我需要這個使用重定向做的,就像這樣:重定向與數組參數Cakephp

return $this->redirect(['controller' => 'Identities', 'action' => 'myMethod', $array]); 

如果我不使用重定向,我不會有myMethod的認爲,我需要它,但我需要有陣列信息在這個視圖上,像做$ this-> set來傳遞數組到視圖。

不過,我得到這個錯誤:

rawurlencode() expects parameter 1 to be string, array given 

我如何將數組作爲參數發送?

回答

1

您可以使用這樣的查詢字符串。

return $this->redirect(['controller' => 'Identities', 'action' => 'myMethod', '?' => ['param1' => 'val1', 'param2' => 'val2']]); 

You can provide routed elements or query string parameters.

Source

+0

我有有像3000個元件的陣列,我不能使用該方法,因爲我需要編寫的所有元素,還陣列可以具有不同的數目取決於元件的計算。我需要將整個數組作爲參數傳遞,類似於$ this-> set函數。 – Vito

+0

您可以在重定向之前將會話元素保存到會話中,然後從會話中加載。 – user3082321

+0

好主意,我會試一試,並會讓你知道。 – Vito