Tôi đang sử dụng Magento Enterprise 1.10.1.1 và cần lấy một số nội dung động trên các trang sản phẩm của chúng tôi. Tôi đang chèn thời gian hiện tại vào một khối để nhanh chóng xem nó có đang hoạt động hay không, nhưng dường như không nhận được thông qua bộ đệm trang đầy đủ.Đang cố gắng lấy nội dung động được đục lỗ thông qua Bộ đệm ẩn trang đầy đủ của Magento
Tôi đã thử nhiều cách thực hiện khác tìm thấy ở đây:
http://tweetorials.tumblr.com/post/10160075026/ee-full-page-cache-hole-punching http://oggettoweb.com/blog/customizations-compatible-magento-full-page-cache/ http://magentophp.blogspot.com/2011/02/magento-enterprise-full-page-caching.html
Bất kỳ giải pháp, những suy nghĩ, ý kiến, lời khuyên được chào đón.
đây là mã của tôi:
app/code/local/Fido/Ví dụ/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Fido_Example>
<version>0.1.0</version>
</Fido_Example>
</modules>
<global>
<blocks>
<fido_example>
<class>Fido_Example_Block</class>
</fido_example>
</blocks>
</global>
</config>
app/code/local/Fido/Ví dụ/etc/cache.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<placeholders>
<fido_example>
<block>fido_example/view</block>
<name>example</name>
<placeholder>CACHE_TEST</placeholder>
<container>Fido_Example_Model_Container_Cachetest</container>
<cache_lifetime>86400</cache_lifetime>
</fido_example>
</placeholders>
</config>
app/code/local/Fido/Ví dụ/Khối/View.php
<?php
class Fido_Example_Block_View extends Mage_Core_Block_Template
{
private $message;
private $att;
protected function createMessage($msg) {
$this->message = $msg;
}
public function receiveMessage() {
if($this->message != '') {
return $this->message;
}
else {
$this->createMessage('Hello World');
return $this->message;
}
}
protected function _toHtml() {
$html = parent::_toHtml();
if($this->att = $this->getMyCustom() && $this->getMyCustom() != '') {
$html .= '<br />'.$this->att;
}
else {
$now = date('m-d-Y h:i:s A');
$html .= $now;
$html .= '<br />' ;
}
return $html;
}
}
app/code/local/Fido/Ví dụ/mẫu/container/Cachetest.php
<?php
class Fido_Example_Model_Container_Cachetest extends Enterprise_PageCache_Model_Container_Abstract {
protected function _getCacheId()
{
return 'HOMEPAGE_PRODUCTS' . md5($this->_placeholder->getAttribute('cache_id') . $this->_getIdentifier());
}
protected function _renderBlock()
{
$blockClass = $this->_placeholder->getAttribute('block');
$template = $this->_placeholder->getAttribute('template');
$block = new $blockClass;
$block->setTemplate($template);
return $block->toHtml();
}
protected function _saveCache($data, $id, $tags = array(), $lifetime = null) { return false; }
}
ứng dụng/thiết kế/frontend/doanh nghiệp/[mytheme] /template/example/view.phtml
<?php echo $this->receiveMessage() ?>
đoạn từ ứng dụng/thiết kế/frontend/doanh nghiệp/[mytheme] /layout/catalog.xml
<reference name="content">
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
<block type="fido_example/view" name="product.info.example" as="example" template="example/view.phtml" />
Bạn không hiển thị mã của 'Fido_Example_Model_Container_Cachetest :: _ getIdentifier()'. Nếu bạn đọc kỹ [http://oggettoweb.com/blog/customizations-compatible-magento-full-page-cache/], bạn sẽ biết rằng đầu ra của khối có lỗ đục lỗ được lưu trong bộ nhớ cache. Ví dụ trên [http://oggettoweb.com/blog/customizations-compatible-magento-full-page-cache/] nó được lưu trữ cho từng khách hàng. Bạn có thể thử trả về 'microtime()' hoặc một cái gì đó tương tự như từ '_getIdentifier()' để làm cho nó trở thành duy nhất. Không chắc chắn ý tưởng này là tốt mặc dù. – Zyava
Cảm ơn lời khuyên của Zyava, nhưng điều đó đã không thực hiện được mẹo - vẫn được lưu trữ. (btw, tôi đã xóa nhầm từ Cachetest.php – rlflow
Bạn có chắc chắn ''HOMEPAGE_PRODUCTS'. md5 ($ this -> _ placeholder-> getAttribute ('cache_id'). $ this -> _ getIdentifier())' luôn là một giá trị mới ? – Zyava