Beispiel #1
0
function route_control($path)
{
    $domain_route_file = PATH_APP . "/include/domain_route.php";
    if (is_file($domain_route_file)) {
        include_once $domain_route_file;
        domain_route($path);
    }
    include_once PATH_PTPHP . "/libs/ui.php";
    $info = pathinfo($path);
    $model_file = str_replace(PATH_WEBROOT, "", $info['dirname']);
    PtApp::$model = PtApp::get_model($model_file);
    $model_file_path = PtLib\get_model_file_path($model_file);
    PtApp::$model_path = $model_file_path;
    if (is_dir(PATH_MODEL) && is_file($model_file_path)) {
        $model_action_name = "view_" . strtolower($info['filename']);
        $model_class_name = PtLib\get_model_class_name(PtApp::$model);
        if (class_exists($model_class_name)) {
            PtApp::$model_class_name = $model_class_name;
            $_reflector = new ReflectionClass($model_class_name);
            PtApp::$model_view_name = $model_action_name;
            if ($_reflector->hasMethod($model_action_name)) {
                $_reflector_func = $_reflector->getmethod($model_action_name);
                $_r_params = array();
                $_r_params_keys = $_reflector_func->getParameters();
                foreach ($_r_params_keys as $_k) {
                    $_r_params[] = $_k->getName();
                }
                $_r_args = array();
                foreach ($_r_params as $_k) {
                    $val = isset($_REQUEST[$_k]) ? trim($_REQUEST[$_k]) : null;
                    $_r_args[$_k] = $val;
                }
                $model_return = $_reflector_func->invokeArgs(new $model_class_name(), $_r_args);
                if ($model_return && is_array($model_return)) {
                    extract($model_return);
                }
            }
        }
    }
    PtApp::$control_path = $path;
    include_once $path;
    exit;
}