2013-05-29 23 views
0

我使用CakePHP的,我這樣做:如何在CakePHP中使用#在url中重定向,而不是%23?

$this->redirect(array('controller' => 'users', 'action' => 'view',$id)); 

在瀏覽器中輸出:... /用戶/視圖/ 42

由於我使用的jQueryUI的標籤,我希望用戶可以重定向到他只是編輯的標籤,所以它應該看起來像:

$this->redirect(array('controller' => 'users', 'action' => 'view',$id."#groups")); 

在瀏覽器中輸出:... /用戶/視圖/ 42%23groups

,但預期編輯結果︰.../users/view/42#groups

問:如何發送正確的URL與#id發送焦點?

我想,如果可能的話,不要使用自定義GET參數,在view.ctp中回顯js以獲得焦點問題。

我希望這是一個CakePHP的問題,也不需要改變一些類似的.htaccess(How to rewrite a URL with %23 in it?

回答

2

請閱讀文檔 http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::url

$this->redirect(array(
    'controller' => 'users', 'action' => 'view', $id, '#' => 'groups')); 
+0

剛剛發佈這個問答後,我發現了在: http://stackoverflow.com/questions/8615516/cakephp-2-redirect-url-with-hashtag 在我的情況下它是: $ this-> redirect(array('controller'=>'users','action'=>'view',$ id,'#'=>「groups」)); (*我在建議的問題標題中搜索'#',而不是'hashtag',但我沒有足夠的聲望來喚醒我自己的問題...... *) –

+0

正如上面已經提到的那樣,您會找到答案閱讀官方文件。 – mark

+0

我有cakephp doc選項卡固定,但我不知道爲什麼這次我在網上搜索第一次沒有找到;我來到這裏。 –

相關問題