Manage URL routes in own php framework

前端 未结 12 2248
盖世英雄少女心
盖世英雄少女心 2021-02-02 16:34

I\'m creating a PHP Framework and I have some doubts...

The framework takes the url in this way: http:/web.com/site/index

It takes the first paramet

12条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-02 17:09

    At some point you will have to check the $_SERVER ['HTTP_HOST'] and a config var defined by the programmer/user wich indicates the subfolder(s) where the app is located, and remove the portion you are not interested in from the rest of the URL.

    You can check this forum post on the codeigniter formus for some hints.

    CodeIgniter uses another different way to route the controller/method internally. You do the routing by the $_SERVER['PATH_INFO'] value. You use the urls like this: myapp.com/index.php/controller/method .

    To avoid showing index.php on the uri you must rely on an Apache rewrite rule, but even with that I think that the CI one is a nice solution, once you have your index file location, you can avoid all the hassle of parsing the URL.

提交回复
热议问题