コード例 #1
0
ファイル: rest.helper.php プロジェクト: steview/moojon
function rest_breadcrumb($attributes = array())
{
    $attributes = try_set_attribute($attributes, 'class', 'breadcrumb');
    $segments = explode('/', moojon_uri::get_match_pattern());
    if ($segments[0] == APP) {
        array_shift($segments);
    }
    $count = count($segments);
    $ul = ul_tag();
    $href = '/';
    for ($i = 0; $i < $count; $i++) {
        $segment = $segments[$i];
        $attributes = $i == $count - 1 ? array('class' => 'last') : array();
        $link = true;
        if (moojon_base::is_symbol($segment)) {
            $symbol_name = moojon_base::get_symbol_name($segment);
            $href .= moojon_request::get($symbol_name) . '/';
            if ($symbol_name != moojon_primary_key::NAME) {
                if (moojon_paths::get_model_path($segment)) {
                    $content = model_from_symbol($segment);
                }
            } else {
                $content = model_from_id($segments[$i - 1]);
            }
        } else {
            if ($i == $count - 1) {
                $link = true;
            }
            $content = title_text($segment);
            $href .= $segment . '/';
        }
        if ($content) {
            if ($i == $count - 1) {
                $ul->add_child(li_tag($content, $attributes));
            } else {
                $ul->add_child(li_tag(a_tag($content, $href), $attributes));
            }
        }
    }
    return div_tag($ul, $attributes);
}