I do the application's URL routing to receive requests from URLs that do not match the actual application files.
index.php

ini_set('display_errors', 1); require_once 'application/bootstrap.php'; 

bootstrap.php

 require_once 'core/Model.php'; require_once 'core/View.php'; require_once 'core/Controller.php'; require_once 'core/Route.php'; Route::start(); 

.htaccess

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php [L] 

Routing in a separate Route.php file to the core directory. In this file, the Route class that will run the methods of the controllers, which in turn will generate page views.

  static function start() { $controller_name = 'Main'; $action_name = 'Index'; $routes = explode('/', $_SERVER['REQUEST_URI']); var_dump($routes); if (!empty($routes[2])) { $controller_name = $routes[2]; } if (!empty($routes[3])) { $action_name = $routes[3]; } $model_name = 'Model' . $controller_name; $controller_name = 'Controller' . $controller_name; $action_name = 'action' . $action_name; $model_file = $model_name . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path)) { include "application/models/" . $model_file; } $controller_file = $controller_name . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { Route::ErrorPage404(); } $controller = new $controller_name; $action = $action_name; print $controller_name; echo "<br/>"; print $action; if (method_exists($controller, $action)) { $controller->$action(); } else { Route::ErrorPage404(); } } function ErrorPage404() { print "trouble"; $host = 'http://' . $_SERVER['HTTP_HOST'] . '/'; header('HTTP/1.1 404 Not Found'); header("Status: 404 Not Found"); header('Location:' . $host . '404'); } 

When called in the browser line, localhost: 63942 / Server / - calls the controller by default and everything works as it should, but when
localhost: 63942 / Server / Main
localhost: 63942 / Server / Main / index
localhost: 63942 / Server / Server
throws out

404 Not Found PhpStorm 2016.1.2

although I have the handling and output of function ErrorPage404() . and in this case, with these requests, the controllers should work and show the views I need.
to the request localhost: 63342 / Server / index.php already throws out my error

project link to github https://github.com/MaximDzhezhelo/Server

Tell me what the problem is, why do I get 404 Not Found for the necessary request in the browser?
How to handle a browser request and configure routing?

  • kogda nabiratete localhost: 63942 / Server / Main / index chto ljit v peremennix $ controller_name i $ action_name? - Vanya Avchyan pm
  • @Vanya Avchyan can not read what is there, because it throws 404 Not Found PhpStorm 2016.1.2, I don’t know how to look in this case, it throws out not my error ( - makson
  • poetomu v mesto Route :: ErrorPage404 (); napishi echo 'methoda netu' ili echo 'fayl ne nayden'. togda budet ponyatno gde obrivaetsya.Esli file nee nayden togda nado iskat v htaccess, poprobuy tam napisat sleduyusche RewriteEngine on RewriteRule! \. (gif | jpeg | jpg | png | css | js) index.
  • pochmu xampp ne polzushsya ili cho nibud drugoe, ya prviy raz viju chtobi polzovalis cheres phpshtorm, eto ne profesionalno, poslushay moy sovet - Vanya Avchyan
  • @VanyaAvchyan need to write here in Russian. What is wrong with phpstorm? - jekaby 8:17 pm

1 answer 1

PhpStorm defaults to using the PHP web server.

Setting up routing for it is described in the PHP documentation :

you are interested in example 3 - router script

In PhpStorm, the setup of the router script is also described in the manual :

in other words, do not guess, but RTFM.

PS (from comments) professionally or not to use the built-in PHP server is such a subjective question that I would not even like to answer it. This is quite ok if you know what you are doing and are not involved in a low-level backend (90% of php coders are not involved). Your job as a professional is to write good, fast, beautiful code.

If IT was “unprofessional”, then putting xampp / lamp is also unprofessional.

By hardcore - you need to have a farm of linux-servers with a full stack of calculations (ansible / git), balancers and replication, and working with them, then you're a pro

"The home coder simply WAS CRAZED when I SEEN THIS PRODUCT"

  • Please tell me about the Use router script check box, do I have to insert. Htaccess (it is not visible through select) or the router script? I read the documentation but did not understand what to do with it and where it should lie. - makson
  • The router script works simply - if it returns false, an attempt is made to read the file, or it returns any other data (or headers), i.e. The router script is such an advanced htaccess for local development, by the way, you can use stackoverflow.com/questions/27765753/… this answer will help, I think. - strangeqargo
  • one
    thank! helped - makson