apify-library icon indicating copy to clipboard operation
apify-library copied to clipboard

Request::getUrlPath returns wrong value

Open elvetemedve opened this issue 13 years ago • 1 comments

If you use Request::setUrlKeyword or Request::setUrlSegment without Request::enableRestfulMapping, than Request::getUrlPath will return the full URI strarting from webroot instead of the expected suffix.

<?php
define('ROOT_DIR', realpath(dirname(__FILE__) . '/../'));
define('APP_DIR', ROOT_DIR . '/app');

require_once ROOT_DIR . '/config/config.php';

try {
    $request = new Request();
    $request->setUrlKeyword('api');  // we want the part after the "api" segment 
    $request->enableUrlRewriting();
    $request->addRoutes(include ROOT_DIR.'/config/routes.php');
    $request->dispatch();
} catch (Exception $e) {
    $request->handleException($e);
}

Request:

GET /apify/api/users

Expected result:

  • controller/action: users/index
  • $request->getUrlPath(): "users"

Actual result:

  • controller/action: index/index
  • $request->getUrlPath(): "apify/api/users"

elvetemedve avatar Feb 09 '12 20:02 elvetemedve

Here is a quick and dirty solution (if using setUrlSegment). Put this in Request.php at the getUrlPath() function:

if (null !== $this->urlSegment) { $i = $this->urlSegment; while ($i>0) { $urlPath=substr($urlPath, strpos($urlPath, '/', 1)); $i--; } }

right before the $this->setUrlPath(urldecode($urlPath));

But remember, this is just a quick solution, not a good one.

mpmf avatar May 14 '12 17:05 mpmf