PHP equivalent of angularJS routing -


in angularjs have index page includes header , footer directly, , div such <div ng-view></div> or <section ui-view></section> partial html pages injected based on routing file in app.js. example:

.config(function ($stateprovider, $urlrouterprovider) {      $stateprovider      .state('home', {         url: "/home",         templateurl: "home/index.html"     })     .state('about', {         url: "/about",         templateurl: "about/index.html"     })     .state('contact', {         url: "/contact",         templateurl: "contact/index.html"     })      $urlrouterprovider.otherwise('/home'); }) 

then whenever clicks hyperlink different part of site, router decides partial gets injected index page. problem urls include hashtags (example.com/#/home) , can rid of configuring website's server run html5mode, can't particular site.

so i'm wondering php equivalent achieve type of routing functionality. figured can use include() header , footer, lost on how handle actual html partials using php.

assuming you're using apache, use:

$_server['request_uri'] 

this php variable holds uri given access current page (i.e., url minus "http://domain.com"). if had large number of possible uris needed handled single php script, use switch statement:

switch ($_server['request_uri']) {     case "/page1.php": // if $_server['request_uri'] contains "/page1.php"         include 'page1.php';         break; // end of case     case "/page2.php":         include 'page2.php';         break;     ...     default:  // if no match found         include '404.php'; } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -