Awesome q2a theme

How to make a Router in an MVC application?

0 like 0 dislike
40 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('/', '[email protected]');

Which way is more flexible and promising?
by | 40 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,187 answers
0 comments
40,796 users