Cakephp 2从$ this-> referer()获取控制器和动作

问题描述 投票:1回答:1

我正在使用CakePhp 2.5,如何使用$this->referer()获取控制器和动作,而无需使用php explode功能。

(int) 0 => 'http:',
(int) 1 => '',
(int) 2 => 'localhost',
(int) 3 => 'mysite',
(int) 6 => 'books',
(int) 7 => 'list'

我的目标是在生产和本地开发中使用相同的代码。

如果我使用爆炸,本地的索引可能与生产不同。

cakephp cakephp-2.0
1个回答
1
投票

您可以使用CakeRoute::parse($url)方法将字符串反转为数组。

https://book.cakephp.org/2.0/en/development/routing.html#CakeRoute::parse

$url = CakeRoute::parse($this->referer());
© www.soinside.com 2019 - 2024. All rights reserved.