2011-11-21 32 views
0

在CakePHP 1.3,當我試圖讓變量得到的URL發送,我可以用這個:CakePHP的1.3 - > 2.0遷移問題 - URL參數

$this->params['url']; 

例子:url = www.mySite.com/messages/get/?var1=1&var2=2

的的$this->params['url'];結果是:

Array => ([url] => Array 
    (
    [url] => messages/get 
    [var1] => 1 
    [var2] => 2 
    ) 
) 

但是當我嘗試使用cakePHP2.0獲得來自同一URL的參數,可以結果是JSON格式:

{"params":{"controller":"messages","named":[],"pass":[],"action":"index","plugin":null}} 

在數組中沒有索引'url',所以你有任何想法如何獲得這些變量發送的URL我發佈使用屬性$ params或其他?

編輯:

我從菜譜cakePHP2.0嘗試這樣做:

<?php 
// url is /posts/index?page=1&sort=title 
$this->request->query['page']; 

// You can also access it via array access 
$this->request['url']['page']; 

,但我得到了同樣的錯誤:

Notice (8): Undefined index: page [APP\Controller\MessagesController.php, line 23] 

Notice (8): Undefined index: page [APP\Controller\MessagesController.php, line 24] 

任何想法?我怎樣才能上的URL發送這樣的變量:

/posts/index?page=1&sort=title 

回答

2

有2.0新Request對象來處理除其他事項外的查詢字符串:

<?php 
// url is /posts/index?page=1&sort=title 
$this->request->query['page']; 

// You can also access it via array access 
$this->request['url']['page']; 

2.0 Request object docs

+0

感謝您的回覆,只工作,我會嘗試這一點,並告訴你回來,如果它的工作原理 – Houcine

+0

我得到了同樣的錯誤,看到我的編輯 – Houcine

+0

好吧,它的作品,我犯了一個愚蠢的錯誤哈哈:)。謝謝 – Houcine

0

看來有一個錯誤。

如果URL /posts/index?&page=1&sort=title(與提取&?後)

+0

使用$ this-> request-> url –