php - How i can set param name in rout of my website? -
i use mvc , oop design project , got problem!
i have number of tanks @ address website:
http://localhost/gamelvl/world-of-tanks/tankguide/ussr/ now want click on each of them description page of tank , address name of tank, namely:
http://localhost/gamelvl/world-of-tanks/tankguide/ussr/st-i how can this? should use param?
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 __construct() { } function index() { $this->view('tankguide/index'); } function ussr() { $this->view('tankguide/ussr'); } } ?> 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
Comments
Post a Comment