gpt4 book ai didi

php - Magento getParam v $_GET

转载 作者:IT王子 更新时间:2023-10-28 23:45:21 24 4
gpt4 key购买 nike

谁能解释功能上和好/坏实践方面的差异,为什么其中一个应该优先于另一个:

$getParam = Mage::app()->getRequest()->getParam('getparam');

v

$getParam = $_GET['getparam'];

最佳答案

两者之间存在显着差异。 $_GET 只是一个数组,如 $_POST。但是,调用 Mage::app()->getRequest()->getParam('param_name') 将允许您访问 GET 和 POST (此处不包括 DELETE 和 PUT) - 请参见下面的代码:

lib/Zend/Controller/Request/Http.php

public function getParam($key, $default = null)
{
$keyName = (null !== ($alias = $this->getAlias($key))) ? $alias : $key;

$paramSources = $this->getParamSources();
if (isset($this->_params[$keyName])) {
return $this->_params[$keyName];
} elseif (in_array('_GET', $paramSources) && (isset($_GET[$keyName]))) {
return $_GET[$keyName];
} elseif (in_array('_POST', $paramSources) && (isset($_POST[$keyName]))) {
return $_POST[$keyName];
}

return $default;
}

此外,如果系统使用 Mage::app()->getRequest()->setParam() 设置其他参数,则可以通过 getParam() 功能。在 Magento 中,您希望始终使用 getParam()

关于php - Magento getParam v $_GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13533936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com