Creating a RESTful API and Website with PHP

I have a PHP application that I wrote earlier that I would like to add a RESTful API. I would also like to expand the site to behave more like a Rails application in terms of the URLs you invoke to get elements in the system.

Is there a way to call elements in PHP using Railsy without creating all types of folders and index pages? How can I call information in PHP without using a GET request tag?

+3
source share
5 answers

If you have some form of mod_rewrite, you can do this quite easily using the .htaccess file.

If you have something like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

, , , . (, hello.html, http://yoursite.com/hello.html)

, , index.php URL-, URL.

, - http://yoursite.com/pages/edit/24, index.php /pages/edit/ 24 url.

, , mod_rewrite,.htaccess index.php, .

+13

PHP REST, CakePHP.

+2

Pascal MARTIN: Zend_Rest_Server REST. RPC URL- REST , .

REST, , REST- PHP. $_SERVER['REQUEST_METHOD'], , ..

+2

, , , REST . , Zend Framework Zend_Rest_Server, REST.

, .

, ( Framework, ), URLrEwriting ; URLS/ /: - (

0

, , -.

mod_rewrite php script. URL . .

, Silex microframework.

0
source

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


All Articles