还有自动设置面包屑,这是面包屑行动的方式方法:
// 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; ?>
这样,如果您有正确的网址结构,您无需设置您的面包屑。