CakePHP 2.3 Web サイトの i18n に このソリューションを使用しました。
ユーザーがこの URL にいる場合:example.com/myController/myAction/param1/param2
へのリンクを提供したいexample.com/eng/myController/myAction/param1/param2
これは、ビュー ファイル内の次のコードでうまく機能します。
<a href="/eng<?php echo $this->here;?>">English</a>
しかし、ユーザーがこの URL にいる場合:example.com/fre/myController/myAction/param1/param2
彼をこの URL にリンクすることはできません:example.com/eng/myController/myAction/param1/param2
これで完全な URL を取得できます。
fullURL = Router::url( $this->here, true );
$strippedURL = str_replace("http://example.com/fre/myController/myAction/param1/param2","myController/myAction/param1/param2",$fullURL)
しかし、私はすべての言語のためにこれを作る必要があります. または、 から最初の 22 文字を取り除くこともでき$fullURL
ます。しかし、それらは良い解決策ではないようです。何か提案はありますか?
編集:ヘルパー/ビューファイル内でこれを使用しました:
function getRelURL() {
$controller = $this->request->params['controller'];
$action = $this->request->params['action'];
$URL = "/".$controller."/".$action."/";
foreach ($this->request->params['pass'] as $p) {
$URL .= urlencode($p)."/";
}
}
より良い代替案をお勧めいただければ幸いです。