oop - How i can create child view for parent view in PHP MVC? -
when type address:
http://localhost/gamelvl/world-of-tanks/tankguide/
i can enter tankguide view. inside folder folder called ussr when create controller , model ussr can not enter address:
http://localhost/gamelvl/world-of-tanks/tankguide/ussr/
now, 1 can give me instructions on whether right thing or other solutions this?
routing app
<?php class app { public $controller = 'index'; public $method = 'index'; public $params = []; function __construct() { if (isset($_get['url'])) { $url = $_get['url']; $url = $this->parseurl($url); $this->controller = $url[0]; unset($url[0]); if (isset($url[1])) { $this->method = $url[1]; unset($url[1]); } $this->params = array_values($url); } $controllerurl = 'controllers/' . $this->controller . '.php'; if (file_exists($controllerurl)) { require($controllerurl); $object = new $this->controller; $object->model($this->controller); if (method_exists($object, $this->method)) { call_user_func_array([$object, $this->method], $this->params); } } } function parseurl($url) { filter_var($url, filter_sanitize_url); $url = rtrim($url, '/'); $url = explode('/', $url); return $url; } } ?>
tankguide controller
<?php class tankguide extends controller { function index() { $this->view('tankguide/index'); } } ?>
core controller
<?php class controller { function __construct() { } function view($viewurl,$data=[]) { require('header.php'); require('views/' . $viewurl . '.php'); require('footer.php'); } function model($modelurl) { require('models/model_' . $modelurl . '.php'); $classname = 'model_' . $modelurl; $this->model = new $classname; } } ?>
project structure
if (method_exists($object, $this->method))
return false given url, because looking method called ussr on tankguide class. either create ussr method on class
Comments
Post a Comment