これがブレッドクラムアクションにあるブレッドクラムを自動的に設定する方法もあります。
// Get the full path without get parameters
$fullPath = $request->getPathInfo();
// get the get parameters
$urlParams = $request->getGetParameters();
// set get parameters as string for url
$this->extend = "";
foreach ($urlParams as $key => $urlParam) {
if (empty($this->extend)) {
$this->extend = "?";
}
this->extend .= $key."=".$urlParam;
}
// Get the URL path and Explode by /
$paths = explode('/', $fullPath);;
$this->paths = $paths;
次に、コンポーネント自体で、パスを介してforeachすることができ、空の場合は続行します。また、ブラウザにリンクがある場合は、常にリンク付きのGET変数を指定してください。
<a href="<?php echo url_for("home").$extend; ?>">Home</a>
<?php foreach($paths as $path):
if(empty($path))
continue;
if(empty($fullPath))
$fullPath = "";
$fullPath .= "/".$path.$extend;
$path = str_replace("-", " ", $path);
?>
<?php if(key($paths->getRawValue()) != (count($paths)-1)): ?>
<a href="<?php echo $fullPath; ?>"><?php echo ucwords($path); ?></a>
<?php else: ?>
<span><?php echo ucwords($path); ?></span>
<?php endif; ?>
このように、正しいURL構造があれば、ブレッドクラムを設定する必要はありません。