本文整理匯總了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;
}
}