-2

我正在尝试加密在 CakePHP 中传递的 URL。我关注了这篇文章(http://bakery.cakephp.org/articles/yuri.salame/2008/07/15/encrypting-urls#),但它不起作用。我知道这是一篇旧文章。我正在使用 CakePHP 2.x

以下是显示的错误:

Notice (8): Undefined index: url [APP/webroot/index.php, line 108]
Warning (4096): Argument 1 passed to Dispatcher::dispatch() must be an instance of CakeRequest, null given, called in /home/xxx/domains/xxx.com/public_html/xxx/v3/app/webroot/index.php on line 110 and defined [CORE/Cake/Routing/Dispatcher.php, line 140]
Warning (4096): Argument 2 passed to Dispatcher::dispatch() must be an instance of CakeResponse, none given, called in /home/xxx/domains/xxx.com/public_html/xxx/v3/app/webroot/index.php on line 110 and defined [CORE/Cake/Routing/Dispatcher.php, line 140]
Notice (8): Trying to get property of non-object [CORE/Cake/Routing/Filter/AssetDispatcher.php, line 45]

我的app/webroot/index.php是(我只显示最后一部分):

App::uses('Dispatcher', 'Routing');

$url = do_decrypt($_REQUEST["url"]); 
$Dispatcher = new Dispatcher(); 
$Dispatcher->dispatch($url);

$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(
    new CakeRequest(),
    new CakeResponse()
);
4

1 回答 1

1

CakePHP 附带的.htaccess文件在 CakePHP 2.x 中已更改。它不再设置url变量,因此在$_REQUEST. 相反,您可以使用$_SERVER['REQUEST_URI']来获取 url。然后必须将此 url 传递给CakeRequest. 所以你的代码看起来像:

App::uses('Dispatcher', 'Routing');

$url = do_decrypt($_SERVER["REQUEST_URI"]); 
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(
    new CakeRequest($url),
    new CakeResponse()
);
于 2013-08-01T09:45:22.057 回答