An example of an MVC controller

后端 未结 6 548
有刺的猬
有刺的猬 2020-12-22 16:09

I have been reading a lot about how and why to use an MVC approach in an application. I have seen and understand examples of a Model, I have seen and understand examples of

6条回答
  •  臣服心动
    2020-12-22 17:06

    getController()) . 'Controller';
            //get method
            $controller_method = strtolower((self::$router->getMethodPrefix() != "" ? self::$router->getMethodPrefix() . '_' : '') . self::$router->getAction());
    
            if(method_exists($controller_class, $controller_method)){
                $controller_obj = new $controller_class();
                $view_path = $controller_obj->$controller_method();
    
                $view_obj = new View($controller_obj->getData(), $view_path);
                $content = $view_obj->render();
            }else{
                throw new Exception("Called method does not exists!");
            }
    
            //layout
            $route_path = self::getRouter()->getRoute();
            $layout = ROOT . '/views/layout/' . $route_path . '.phtml';
            $layout_view_obj = new View(compact('content'), $layout);
            echo $layout_view_obj->render();
        }
    
        public static function redirect($uri){
            print("");
            exit();
        }
    }
    

提交回复
热议问题