, URL- .
, id: 123 URL-, /search/id/123. $app->Property->search($array) MySQL. script JSON, Ajax JavaScript . JSON, PHP/HTML PHP .
<?php
$query = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$qs = array();
foreach ($query as $key=>$value) $qs[$key] = urldecode(htmlspecialchars($value));
array_shift($qs);
switch ($val = array_shift($qs)) {
case "search":
$params = array();
$field = true;
while (!is_null($val=array_shift($qs))) {
if ($field) $params[-1] = $val;
else $params[$params[-1]] = urldecode($val);
$field = !$field;
}
unset($params[-1]);
$result = $app->Property->search($params);
header('Content-type: application/json');
echo json_encode($result, JSON_FORCE_OBJECT);
exit;
break;
...
This script works along with a .htaccessscript that redirects all requests to my file index.php. Index.php at some point loads this file controller.php, which processes the URLs and loads the page depending on the URL.
Here is the .htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
source
share