如果我们想做一些操作,但是不想通过magento内部走

可以这么操作

app/mage.php是magento的入口文件,加载了这个文件就可以使用magento里面的东西了

下面是代码示例:

1

1 require_once($_SERVER['DOCUMENT_ROOT'].'/app/Mage.php');
2 $app = Mage::app();
3 Mage::getSingleton('core/session', array('name' => 'frontend'));

2

得到static block

require("../app/Mage.php");

echo Mage::app()->getLayout()->createBlock('cms/block')->setBlockId('tagsearch')->toHtml() ;

3

$cart = $app->getLayout()->getBlockSingleton('checkout/cart_sidebar')->setTemplate("checkout/topcart.phtml")->toHtml();

 

1 <?php echo $cart; ?> <!-- we now echo the cart this will bring back the following -->
2 <div id="minibasket">
3 <div id="introlley">
4  <a href="/checkout/cart" title="View/Edit Your Basket">  2 items<br />
5  total: <span>£24<span>.98</span></span></a>
6 </div>
7 <a href="/checkout/cart" title="View and Edit Basket"><img src="/images/trollystates/3b.png" width="46" height="33" alt="Trolley" id="trollied" /></a>
8 <div id="checkitout"><a title="Checkout"  href="/checkout/onepage/">Proceed to<br /><span>Checkout &raquo;</span></a></div>
9 </div>

这样可以更加方便灵活的使用magento的机制!