Пример #1
0
 function get_view_for_action($action)
 {
     $template = $this->get_template_base() . '/' . url_name($action);
     return $this->get_view($template);
 }
Пример #2
0
 function to_param()
 {
     return array('controller' => url_name(get_class($this)), 'action' => 'show', 'id' => $this->get_id());
 }
Пример #3
0
function render_partial($action, $object = false, $collect = false, $controller = false)
{
    #if the controller is an array, use it and ignore the rest
    if (is_array($action)) {
        if (array_key_exists('object', $action)) {
            $object = $action['object'];
        }
        if (array_key_exists('collect', $action)) {
            $collect = $action['collect'];
        }
        if (array_key_exists('controller', $action)) {
            $controller = $action['controller'];
        }
        if (array_key_exists('action', $action)) {
            $action = $action['action'];
        }
    } else {
        if ($controller == false) {
            $controller = params('controller');
        }
    }
    # set the template and object name
    $slashloc = strrpos($action, '/');
    if ($slashloc !== false) {
        $objectname = substr($action, $slashloc + 1);
        if ($action[0] == '/') {
            $template = substr(substr($action, 0, $slashloc) . '/_' . $objectname, 1);
        } else {
            $template = url_name($controller) . '/' . substr($action, 0, $slashloc) . '/_' . $objectname;
        }
    } else {
        $template = url_name($controller) . '/_' . $action;
        $objectname = $action;
    }
    $view = ViewFactory::make_view($template);
    # include the helpers
    if (file_exists(PROJECT_ROOT . '/app/helpers/app.php')) {
        include_once PROJECT_ROOT . '/app/helpers/app.php';
    }
    if (file_exists(PROJECT_ROOT . '/app/helpers/' . $controller . '.php')) {
        include_once PROJECT_ROOT . '/app/helpers/' . $controller . '.php';
    }
    # if it's a collection, call it for each item in the obj
    $objectname = var_name(class_name($objectname));
    if ($collect === true) {
        foreach ($object as $k => $v) {
            echo $view->parse_partial($objectname, $v);
        }
    } else {
        echo $view->parse_partial($objectname, $object);
    }
}