您的位置:首页 > 其它

26. Magento 常用(1)

2015-12-09 16:25 204 查看
/article/3741723.html

众所周知,Magento的多店铺功能非常强大,通过多店铺功能,我们可以在一个Magento应用当中创建在外观上看来完全不相关联的多个店铺,并且可以绑定不同的域名。在Magento的开发当中,经常需要获取当前所在店铺的一些相关信息,例如店铺id,店铺名称及当前店铺所属Website的ID值。通过Magento的Mage类,我们可以获取到关于店铺的所有信息。



//获取所有商店信息
Mage::getModel('adminhtml/system_store')->getStoreCollection(); //获取所有,包括未激活的


//获取店铺对象
Mage::app()->getStore(); //获取激活的




//获取当前店铺ID
Mage::app()->getStore()->getStoreId();




//获取当前店铺Code,该Code在创建店铺时填写
Mage::app()->getStore()->getCode();




//获取当前店铺所属的Website ID
Mage::app()->getStore()->getWebsiteId();




//获取当前店铺的Name
Mage::app()->getStore()->getName();




//获取当前店铺的状态
Mage::app()->getStore()->getIsActive();




//获取当前店铺的URL
Mage::app()->getStore()->getHomeUrl();


2.获取配置文件的值



<?xml version="1.0"?>

<config>
<default>
<some>
<random>
<xpath>Here is default</xpath>
</random>
</some>

<catalog>
<mypage>
<name>myname</name>
<age>100</age>
<address>earth</address>
</mypage>
</catalog>
</default>

<stores>
<french>
<some>
<random>
<xpath>here is french store</xpath>
</random>
</some>
</french>
</stores>

<global>
<test1>
<haha1>100</haha1>
</test1>
</global>

<frontend>
<test2>
<haha2>200</haha2>
</test2>
</frontend>

<admin>
<test3>
<haha3>300</haha3>
</test3>
</admin>
</config>


Mage::getConfig()->getNode(绝对路径);






配置文件中的值,都为下面类的元素:



3. 创建基本类:

//1.创建 model
Mage::getModel('uri');

//2.创建 helper
Mage::helper('uri');

//3.创建 block
Mage::app()->getLayout()->createBlock('uri);

//4.手动创建block,设置模板

class Www_First_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$block = Mage::app()->getLayout()
->createBlock('core/template')
->setTemplate('first/first.phtml')->toHtml();
$this->getResponse()->setBody($block);
}
}

在 controller 中创建 block 也可以用 $this->getLayout()->createBlock('uri');














4.获取表名





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: