简体   繁体   English

Magento:如何在CMS页面中包含php调用

[英]Magento: How to include a php call in the CMS pages

Following the instructions from this page: 按照此页面的说明操作:

http://www.magento.cc/how-to-use-php-on-a-cms-page.html http://www.magento.cc/how-to-use-php-on-a-cms-page.html

1) i declared the module in the app/etc/modules : 1)我在app / etc / modules中声明了模块

<?xml version="1.0"?>
<config>
    <modules>
        <Stock_status>
            <active>true</active>
            <codePool>local</codePool>
</Stock_status>
</modules>
</config>

2) Then i created the config.xml in app\\code\\local\\Stock\\status\\Custom\\etc with these contents in it: 2)然后我在app \\ code \\ local \\ Stock \\ status \\ Custom \\ etc中创建了config.xml ,其中包含以下内容:

<?xml version="1.0"?>
<config>
<global>
<blocks>
<Stock_status>
<class>Stock_status_Block</class>
</Stock_status>
</blocks>
</global>
</config>

3) afterwards i created a test.php in app/code/local/Stock/status/Custom/Block file with these contents in it: 3)之后我在app / code / local / Stock / status / Custom / Block文件中创建了一个test.php ,其中包含以下内容:

<?php
class Stock_status_Block_Test extends Mage_Core_Block_Abstract
{
protected function _toHtml()
{
.Mage::helper('customstockstatus')->getListStatus($_product->getId()).
return $html;
}
}

and finally 4) i went in a cms page to see if it works by putting this value in: 最后4)我进入了一个cms页面,通过将此值放入以下内容来查看它是否有效:

{{block type="Stock_status_Custom/test" ListStatus="02"}}

This line of code should return me the stock status of a specific product (in this example, the product with the ID 02) 这行代码应该返回特定产品的库存状态(在本例中,ID为02的产品)

BUT it doesn't work. 但它不起作用。 What have i done incorrectly? 我做错了什么? Can someone please help me? 有人可以帮帮我吗?

These are an unnecessary works, you can simply call the php file by adding the following line into that cms page content 这些是不必要的工作,您可以通过将以下行添加到该cms页面内容中来简单地调用php文件

   {{block type="core/template" template="page/urfile.phtml"}}

Then create file under the page directory 然后在页面目录下创建文件

go to Magento Admin->CMS->Pages 转到Magento Admin-> CMS-> Pages

  1. Click Add New Page 单击“添加新页面”
  2. Input Page Title 输入页面标题
  3. Input URL Key 输入URL密钥
  4. Right Content inside (body) 内容正确(正文)
  5. paste your code. 粘贴你的代码。

Hope this help 希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM