示例#1
0
function __autoload($class)
{
    $class_path = moojon_paths::get_class_path($class);
    $class_paths = array($class_path);
    if (!$class_path) {
        $class_path = moojon_paths::get_model_path($class);
        $class_paths[] = $class_path;
    }
    if (!$class_path) {
        $class_path = moojon_paths::get_base_model_path($class);
        $class_paths[] = $class_path;
    }
    if (!$class_path) {
        $class_path = moojon_paths::get_interface_path($class);
        $class_paths[] = $class_path;
    }
    if (!$class_path) {
        $class_path = moojon_paths::get_column_path($class);
        $class_paths[] = $class_path;
    }
    if ($class_path) {
        require_once $class_path;
    } else {
        throw new moojon_exception("Not found ({$class})");
    }
}
示例#2
0
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);
}
 private function get_relationship_routes()
 {
     $relationship_routes = array();
     $model_class = moojon_inflect::singularize($this->resource);
     if ($path = moojon_paths::get_model_path($model_class)) {
         require_once $path = moojon_paths::get_model_path($model_class);
         $model = new $model_class();
         foreach ($model->get_relationships() as $relationship) {
             $foreign_table = $relationship->get_foreign_table();
             if (moojon_routes::has_rest_route($foreign_table)) {
                 $relationship_route = moojon_routes::get_rest_route($foreign_table);
             } else {
                 $relationship_route = new moojon_rest_route($foreign_table, array_merge($this->params, array('controller' => $foreign_table)));
             }
             $relationship_routes[] = $relationship_route;
         }
     }
     return $relationship_routes;
 }