2016-11-20 32 views
1

我需要發送帶有鏈接的文本電子郵件,供用戶單擊。這是用戶驗證電子郵件。我遇到的問題是URL助手不斷逃離角色。我覺得我已經嘗試了以下各種可能的組合,但無濟於事。在CakePHP中轉義URL Helper

echo $this->Url->build([ 
    "controller" => "Users", 
    "action" => "verify", 
    "?" => ['email' => $email, 'hash' => $hash] 
    ],[ 
    "escape" => false, 
    "fullBase" => true 
    ]); 

這導致http://www.mydomain.co.uk/users/verify?email=chris%40domain.co.uk&hash=b56a4eea3b495db226888f2f89e7678f的 '@' 和 '&' charachters是beeing逃脫哪裏。

此問題的另一個問題是,蛋糕不能訪問哈希變量,但它可以電子郵件,即。

echo $this->request->query('hash') //doesn't print anything 
echo $this->request->query('email') //prints email with the @ symbol 
+1

特別是你使用的是什麼版本的蛋糕?該文檔指出傳遞數組作爲第二個參數僅在3.3.5中添加。 –

+0

@GregSchmidt我正在使用3.2.13。這是否意味着在3.3.5之前,你不能在構建函數中轉義特殊字符?如果是這樣,你知道另一種方式來做到這一點嗎? – ChrisBull

回答

0

感謝Greg Schmidt指出版本不一致。

僅供參考;您只能使用CakePHP 3.3.5及更高版本的轉義(截至2016年11月)。

我用htmlspecialchars_decode($這個 - > URL->建立())來解決這個問題