当lightspeed.php
在目录中看到相应的缓存文件时var/lightspeed
,它会加载并解析。现在它看到,有些内容需要是动态的。因此,通过之前更改lightspeed.php
的方式向 Magento 发出虚假的 GET 请求。看看下面的代码:Mage::run()
$_REQUEST['URI']
光速.php:
self::report("attempting to retrieve hole punched content from {$data[2]}");
$_SERVER['originalRequestUri'] = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = self::$request_path . "/" . $data[2];
你可以在这里看到我如何复制$_SERVER['REQUEST_URI']
到$_SERVER['originalRequestUri']
. 下面我们一起来看看
孔控制器.php:
$originalRequest = new Mage_Core_Controller_Request_Http('http://example' . $_SERVER['originalRequestUri']);
$originalRequest->setPathInfo()->setDispatched(false);
Mage::getModel('core/url_rewrite')->rewrite($originalRequest);
$params = explode('/', $originalRequest->getPathInfo());
/* IF YOU HAVE SOME ADDITONAL PARAMS PASSED AS /color/1/size/2,
THIS PARAMS SHOULD BE ALSO PARSED AND SET TO REQUEST OBJECT
for ($i = 3, $l = sizeof($params); $i < $l; $i+=2) {
$originalRequest->setParam($params[$i], isset($params[$i + 1]) ? $params[$i + 1] : '');
}
*/
if ($params[1] == 'product') { // if parsed URL is product view page URL
$productId = $originalRequest->getParam('id');
$product = Mage::getModel('catalog/product')->load($productId);
Mage::register('current_product', $product);
}
耶!现在我们current_product
在注册表中。您可以创建所需的块。