Routing in PHP vs. Routing in Rails

I have been working on PHP for the past 1 year, and I'm currently learning Rails.

On the rails: - Routing takes an incoming URL and decodes it into a set of parameters that Rails uses to send to the appropriate controller and action

for instance

 rs.recognize_path "/blog/show/123"
 {:controller=>"blog", :action=>"show", :id=>"123"}

I'm right?

We mention this (recorded) line of code on our .rb routes in the config directory to tell rails how to handle a request like "/ blog / show / 123" using this line of code.

map.connect "blog/show/:id", :controller => "blog", :action => "show", :id => /\d+/

Now in PHP, when we do something like this

www.example.com/profile.php?profile_id=2

How is the request sent to the requested page? So, I never wrote anything for routing in PHP, so how was this request processed by hss? How is routing done in PHP (what did I miss while learning / working in PHP)?

, , . , , - .

+3
5

PHP , profile.php. - ( ) .

Rails URL- , . Rails blog BlogController. Rails , , , apps/controllers/blog_controller.rb.
, show show BlogController, show .
Rails Rails.

,

  • PHP URL- : .
  • Rails URL- ( /), .
+3

Rails PHP - ; . , , :

  • - - , (, Apache, nginx, Eebrick)
  • Interpreter - , (, Ruby, PHP, Perl)
  • Web framework - , - (, Rails, CakePHP, Code Igniter, Django).

- URL , :

http://example.com/example.php -> /var/www/example.php
http://example.com/other.rb -> /var/www/other.rb

(, ..) . ( ?a=foo&b=bar). - URLS . , Apache mod_rewrite, , , URL- URL-. , Apache:

RewriteRule /foo/(.*)$ /index.php?id=$1

, /foo/, index.php URL id:

http://example.com/foo/bar       -> /var/www/index.php?id=bar
http://example.com/foo/other/bar -> /var/www/index.php?id=other/bar

, , . Rails- URL- . PHP , . , CakePHP /posts/show/ 2 show (2) PostsController. Router, .

, ;)

+6
www.example.com/profile.php?profile_id=2

? / URI . URI , www.example.com/profile.php , GET - profile_id=2. PHP $_GET, :

array(
    'profile_id' => 2
)

profile.php script , $_GET['profile_id'].

"Rails-routed URI", , SEO, : , Rails, .htaccess , RRI- URI profile.php.

. ( , - ) , , Zend Framework Router.

+2

Rails, - , - "" . , , routing.

PHP- HTTP- , . MVC , , , (, , URL-) .

+1

, .

.

.

/profile.php?profile_id=2 www.example.com

php

Similar.

list($controller,$blog,$id)=explode("/","/blog/show/123");
0
source

Source: https://habr.com/ru/post/1742416/


All Articles