本文整理汇总了PHP中app\Page::parent方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::parent方法的具体用法?PHP Page::parent怎么用?PHP Page::parent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Page
的用法示例。
在下文中一共展示了Page::parent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: walk
/**
* Walk thru the pages tree and return the navigation html and set currentPage is found
*
* WARNING: DEPRECIATED!!! WILL BE REMOVED IN 1.0 RELEASE!
* Should be done in your Page model, See Page.php in samples
*/
function walk($parent, $depth, $ids, $url = '', $hidden = false)
{
# The id might not exist if it's the domain root for example
if (!isset($ids[$depth])) {
$ids[$depth] = '';
}
# Fetch all pages
$pages = \App\Page::parent($parent)->get();
# Return if no pages found to prevent empty navigation <ul></ul>
if (!count($pages)) {
return;
}
# Create the navigation html
$nav = '<ul class="nav' . $depth . '">';
foreach ($pages as $page) {
# Set currentPage if it's this one but only if $depth equals the actual amount of ids
if ($ids[$depth] == $page->url && $depth == count($ids) - 1) {
$this->currentPage = $page;
}
# Add page to navigation html and add active class when needed
if (!$page->hidden) {
$nav .= ' <li' . ($ids[$depth] == $page->url ? ' class="active"' : '') . '>';
$nav .= '<a href="' . $url . $page->url . '">' . $page->title . '</a>';
}
# Check if this page has subpages and add them
$nav .= $this->walk($page->id, $depth + 1, $ids, $url . $page->url . '/', $page->hidden || $hidden);
# Finalize navigation html
if (!$page->hidden) {
$nav .= '</li>';
}
}
# Finalize navigation html and return it
$nav .= '</ul>';
if (!$hidden) {
return $nav;
}
}