Hello everyone

Using the following code results in some unexpected behavior.

<?php
set_include_path(
   dirname(__FILE__) . '/../Zend-2.0/incubator/library' . PATH_SEPARATOR
   . dirname(__FILE__) . '/../Zend- 2.0/library' . PATH_SEPARATOR
   . get_include_path()
);

include "Zend.php";
Zend::loadClass('Zend_Controller_Front');
Zend::loadClass('Zend_Controller_RewriteRouter');

$controller = Zend_Controller_Front::getInstance();
$controller->setControllerDirectory("controllers");

$router = new Zend_Controller_RewriteRouter();
$router->addRoute("searchdetails",     new
Zend_Controller_Router_Route(":query/:model/:style",
array("controller"=>"search","action"=>"details"),
array("query"=>"[a-zA-Z0-9_]+", "model"=>"[a-zA-Z0-9_]+", "style"=>"\d+")));

$router->addRoute("searchmodels",     new
Zend_Controller_Router_Route(":query/:model",
array("controller"=>"search","action"=>"index"),
array("query"=>"[a-zA-Z0-9_]+", "model"=>"[a-zA-Z0-9_]+")));
$router->addRoute("search",         new
Zend_Controller_Router_Route(":query",
array("controller"=>"search","action"=>"index"),
array("query"=>"[a-zA-Z0-9_]+")));

$request = new Zend_Controller_Request_Http();
// IF THE REQUEST IS FOR http://site.dev/san_diego
echo $request->getRequestUri();
//returns '/san_diego'
echo $request->getBaseUri();
//returns ''
echo $request->getPathInfo();
//returns 'o'
//I would expect it to return 'san_diego'
?>

in the Zend_Controller_Http_Request file I see the following line which is
causing the behavior.

Line 464: if ((null !== $baseUrl) && (false === ($pathInfo =
substr($requestUri, strlen($baseUrl) - 1)))) {

strlen($baseUrl) returns -1 making substr() take the last letter of
$requestUri as $pathInfo.

Here are the contents of the $_SERVER variable

   [SERVER_NAME] => site.dev
   [HTTP_HOST] => site.dev
   [REQUEST_URI] => /san_diego
   [SCRIPT_NAME] => /index.php
   [PHP_SELF] => /index.php

--
Michael DePetrillo
[EMAIL PROTECTED]
Mobile: (858) 761-1605
AIM: klassicd

Reply via email to