2011-10-19 32 views
0

如何獲得下列文件 frontend/enterprise/default/template/page/html/header.phtmlfrontend/base/default/template/page/template/links.phtmlfrontend/enterprise/default/template/checkout/cart/cartheader.phtml拼搶Magento的phtmls同時保持數據完整

的Magento的外面,仍然有處理日期完整的內容。 就像我的意思是仍然顯示用戶'我的購物車(5)'的正確數量的項目,或者在標題中顯示'Welcome,volkan yavuz'並仍然顯示用戶的名稱。

爲什麼我要這個?

我有一個獨立於Magento的zend應用程序,我們試圖結合頁眉和頁腳,所以我們將它們放在一個地方。我們需要從這個zend應用程序調用Magento頭文件。

到目前爲止,我在Magento中創建了一個調用這些文件(phtml)的自定義API,但似乎無法獲取這些處理的數據(如當前會話/用戶的購物車號碼或歡迎名字姓氏消息)

回答

1

爲了讓這些正確的數據來呈現&狀態,他們必須有正確的渲染環境。

<?php 
include 'app/Mage.php'; 
Mage::app('store_code'); 

//Load the session so we get quotes. 
Mage::getSingleton('core/session', array('name' => 'frontend'))->start(); 
/* 
    see Mage_Core_Controller_Varien_Action::preDispatch() 
    and Mage_Core_Controller_Front_Action::preDispatch() 
*/ 

//For each block you wish to render, you could do the following: 
$output = Mage::app()->getLayout() 
        ->createBlock('block/type') 
        ->setTemplate('template/path.phtml') 
        ->toHtml(); 

您可以選擇讓您的所有塊的包含塊,設置您塊作爲孩子的塊,製作合適的模板& getChildHtml()其中的呼叫,然後您只需在該塊上撥打toHtml()即可。

HTH!

相關問題