還有自動設置麪包屑,這是麪包屑行動的方式方法:
// 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; ?>
這樣,如果您有正確的網址結構,您無需設置您的麪包屑。