How to make a Router in an MVC application?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
15 views
Did your mvc framework, but do not know how best to organize the Router.
1) to Use $_GET parameters /site/?controller=news&action=index
2) to Split the URL into segments:

$routes = explode('/', $_SERVER['REQUEST_URI']);
if ( !empty($routes[2]) ) {
$controllerName = $routes[2]; //controller Name
}

if ( !empty($routes[3]) ) {
$actionName = $routes[3]; //Name of action
}

3) to Prescribe ranting in an array:
$routes = array(
'news' => 'news/index',
'news/([0-9])' => 'news/view'
)
Then the cycle using regular expressions to find matches in $_SERVER['REQUEST_URI'], and accordingly for further action.
1 and 2, in the case of controller and action are determined automatically.
3 I Need to write ranting beforehand, as in laravel Route::get('/', 'maincontroller@index');

Which way is more flexible and promising?
by | 15 views

1 Answer

0 like 0 dislike
I semsester 2 and 3. If no route list to determine automatically
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
4 answers
asked Apr 24, 2019 by webninja_surgut
0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,405 users