As you probably saw, when I started my little front controller project I used absolute URLs because what it matter in the beginning was just to have a working PHP website on my local computer.
When I copied the project to my computer at work I had to have theh same path "127.0.0.1/myFrontController/" and from this base address it was computed the relative URL to identify the route in router.xml.
As I am getting closer to version 1.0 I need to make my website independent from where it will be deployed. In order to archive this I will be using virtual hosts feature.
If you are using EasyPHP as I do, Install the module Virtual Host Manager from: http://www.easyphp.org/save-module-virtualhostsmanager-vc9-latest.php or have look here http://www.apptools.com/phptools/virtualhost.php
- create a virtual host called as you wish
Do some changes in the code:
- 'Location:http://127.0.0.1/myFrontController/admin/home' changed to "Location: /admin/home" in Admin.class.php
- edit all links to be relative
- use directly the $_SERVER['REQUEST_URI'] instead erasing "/myFrontController" in FrontController class constructor.
$request_uri=$_SERVER['REQUEST_URI'];
$this->relative_url=substr($request_uri, strpos($request_uri, '/', 1));
replaced with:
$this->relative_url=$_SERVER['REQUEST_URI'];
No comments:
Post a Comment