久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Magento 中設(shè)置全局變量,GUI 方式?

Setting a global variable in Magento, the GUI way?(在 Magento 中設(shè)置全局變量,GUI 方式?)
本文介紹了在 Magento 中設(shè)置全局變量,GUI 方式?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我最近開(kāi)始在客戶(hù)的網(wǎng)上商店中使用 Magento,但仍然需要掌握它的系統(tǒng).

I've recently started using Magento for a client's webshop, and still need to get to grips with its systems.

網(wǎng)上商店應(yīng)該有多個(gè)鏈接,并且還可以從公司網(wǎng)站所在的另一個(gè)域中獲取信息.我不想對(duì)域名或 URL 進(jìn)行硬編碼,而是在某個(gè)地方定義它并在整個(gè)網(wǎng)上商店的 phtml 模板中使用該值.當(dāng)我們?cè)陂_(kāi)發(fā) URL、暫存 URL 和生產(chǎn) URL 之間移動(dòng)站點(diǎn)時(shí),這樣可以輕松調(diào)整它.

The webshop should have several links to and also grab info from another domain, where the corporate website is located. I would prefer not to hardcode the domain name or URL but instead define it at some place and use that value in the phtml templates throughout the webshop. This makes it easy to adjust it when we move the site between dev, staging and production URL's.

任何人都可以建議 Magento 這樣做嗎?最好我們可以在后端的商店配置 GUI 中添加一個(gè)字段,類(lèi)似于設(shè)置 {{base_url}} 的方式.還是我的想法錯(cuò)了?

Can anyone suggest the Magento way of doing this? Preferably we could add a field to the Store's Config GUI in the backend, similar to the way the {{base_url}} is set. Or maybe I'm thinking the wrong way?

推薦答案

Magento 為自定義配置值提供(相對(duì))簡(jiǎn)單的支持.我發(fā)現(xiàn)實(shí)現(xiàn)此目的的最佳方法是創(chuàng)建一個(gè)單獨(dú)的 magento 模塊,其中包含所有自定義配置值.

Magento offers (relatively) easy support for custom configuration values. The best way I've found to accomplish this is to create a single magento module that holds all your custom configuration values.

像 Magento 一樣,有很多步驟,任何一個(gè)錯(cuò)誤都可能絆倒你(或我!).

Like anything Magento, there are a lot of steps, and any one being wrong could trip you (or me!) up.

首先,您需要設(shè)置一個(gè) magento 模塊來(lái)保存所有自定義配置值.創(chuàng)建一個(gè) magento 模塊涉及

First, you'll want to setup a magento module to hold all your custom configuration values. Creating a magento module involves

  1. 在 app/etc/modules 中創(chuàng)建一個(gè) xml 文件
  2. 在 app/code/local/Companyname 中創(chuàng)建文件夾結(jié)構(gòu)

Companyname 是一個(gè)唯一的字符串,用作命名空間,大多數(shù) magento 教程建議您在此處使用您的公司名稱(chēng).出于本教程的目的,我將使用Stackoverflow".無(wú)論您在何處看到字符串 Stackoverflow,都將其替換為您自己的唯一字符串.

Companyname is a unique string that serves as a namespace, and most magento tutorials recommend you use your company name here. For the purposes of this tutorial, I'll use "Stackoverflow". Wherever you see the string Stackoverflow, replace it with your own unique string.

因此,對(duì)于第 1 步,在 app/etc/modules 中創(chuàng)建一個(gè)名為Stackoverflow_Customconfig.xml"的文件,并將以下內(nèi)容放入

So, for step 1, create a file at app/etc/modules named "Stackoverflow_Customconfig.xml", and place the following inside

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

隨機(jī) Magento 提示:Magento 系統(tǒng)的某些部分認(rèn)為空格很重要,因此最好不要在屬性值中包含空格(true</active> vs. true <;/活動(dòng)>

Random Magento Tip: There are parts of the magento system that consider whitespace significant, so it's always best to include no whitespace with your attribute values (<active>true</active> vs. <active> true </active>

接下來(lái),創(chuàng)建以下文件夾

Next, create the following folder

mkdir app/code/local/Stackoverflow/Customconfig
mkdir app/code/local/Stackoverflow/Customconfig/etc

并在

app/code/local/Stackoverflow/Customconfig/etc/config.xml

有以下內(nèi)容

<?xml version="1.0"?>
<config>
    <modules>
        <Stackoverflow_Customconfig>
            <version>0.1.0</version>
        </Stackoverflow_Customconfig>
    </modules>
</config>

恭喜,您剛剛設(shè)置了一個(gè)新的 Magento 模塊.如果您清除 magento 緩存并轉(zhuǎn)到

Congratulations, you've just setup a new Magento Module. If you clear your magento cache and go to

System -> Configuration -> Advanced -> Disable Modules Output

您應(yīng)該會(huì)看到列出的模塊.

you should see your module listed.

接下來(lái),我們將添加一個(gè) system.xml 文件.此文件用于向 magento 添加自定義配置值,您可以在 magento 請(qǐng)求周期中的任何位置獲取該值.在

Next, we're going to add a system.xml file. This file is used to add a custom configuration value to magento, which you'll be able to grab anywhere you want during the magento request cycle. Add a file at

app/code/local/Stackoverflow/Customconfig/etc/system.xml

包含以下內(nèi)容

<config>
    <sections>
        <design>
            <groups>
                <my_or_their_group translate="label">
                    <label>A grouping of config values.  Make your own, or us an existing group.</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>50</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>0</show_in_website>
                    <show_in_store>0</show_in_store>
                    <fields>
                        <my_config translate="label">
                            <label>This will be my config's label</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>50</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </my_config>
                    </fields>
                </my_or_their_group>
            </groups>
        </design>
    </sections>
</config>   

是您的配置將在其中顯示的部分的名稱(chēng).常規(guī)、網(wǎng)頁(yè)、設(shè)計(jì)、貨幣設(shè)置等".總的來(lái)說(shuō),這將是標(biāo)題的小寫(xiě)版本,即General"變?yōu)間eneral",Design"變?yōu)閐esign".如果您不確定這個(gè)外部標(biāo)簽應(yīng)該是什么,請(qǐng)搜索核心 magento 模塊.即,對(duì)貨幣設(shè)置"的 grepping 顯示在

<design> is the name of the section your config will be displayed in. "General, Web, Design, Currency Setup, etc." By and large, this will be a lower-case version of the title, i.e. "General" becomes "general", "Design" becomes "design". If you're not sure what this outer tag should be, search through the core magento modules. i.e., grepping for "Currency Setup" reveals a mention in

app/code/core/Mage/Directory/etc/system.xml
<currency translate="label" module="directory">
    <label>Currency Setup</label>

所以你會(huì)使用標(biāo)簽<currency/<,而不是更直觀的<currency_setup/>

So you'd use the tag <currency /<, and not the more intuitive <currency_setup />

是您的配??置變量將在其中顯示的組的名稱(chēng).組是包含配置字段的 Ajax 下拉列表.例如,常規(guī)"部分有一個(gè)國(guó)家選項(xiàng)"組和一個(gè)本地選項(xiàng)"組.如果您不確定如何在現(xiàn)有組中放置值,請(qǐng)?jiān)俅螜z查現(xiàn)有核心模塊.

<my_or_their_group translate="label"> is the name of the group your config variable will show up in. Groups are the Ajax drop downs that contain config fields. For example, the General section has a "Country options" group and a Local options" group. Again, check existing core modules if you're unsure how to place a value in an existing group.

您還會(huì)注意到這里有一個(gè) translate 屬性,以及相應(yīng)的標(biāo)簽標(biāo)記.這允許您在 HTML 界面中使用您想要的任何字符串作為組標(biāo)題,但在內(nèi)部將該名稱(chēng)保留為有效的 XML 標(biāo)記名稱(chēng).我們的標(biāo)簽被命名為

You'll also notice a translate attribute here, along with a corresponding label tag. This allows you to use any string you want in the HTML interface as a group title, but internally keep the name a valid XML tag name. Our tag is named

<my_or_their_group />

但在界面中,群組會(huì)有標(biāo)題

but in the interface, the group will have the title

一組配置值.建立您自己的或我們現(xiàn)有的群組.

A grouping of config values. Make your own, or us an existing group.

最后,<my_config translate="label">是 yoru conifg 值的名稱(chēng).再次注意translate 屬性.與上述相同的規(guī)則適用.

Finally, <my_config translate="label"> is the name of yoru conifg value. Again, notice the translate attribute. The same rules as above apply.

需要其他 xml 結(jié)構(gòu),并且(主要)用于控制將用于您的配置的 HTML 輸入類(lèi)型.如果需要特定的界面元素,請(qǐng)?jiān)诤诵哪K中找到示例并復(fù)制 XML 結(jié)構(gòu).

The other xml structure is needed, and is (mostly) used to control what kind of HTML inputs will be used for your config. If you want a particular interface element, find an example in the core module and copy the XML structure.

這將允許您在 Magento GUI 界面中設(shè)置和查找配置值.您可以使用全局 Mage 對(duì)象的靜態(tài) getStoreConfig 方法并指定配置值的 URI 來(lái)檢索您的值.URI 是使用配置的部分/組/名稱(chēng)創(chuàng)建的.

This will allow you to set and lookup config values in the Magento GUI interface. You can retrieve your values using the static getStoreConfig method of the global Mage object and specifying the URI of your config value. The URI is created using the section/group/name of your config.

Mage::getStoreConfig('design/my_or_their_group/my_config');     

這篇關(guān)于在 Magento 中設(shè)置全局變量,GUI 方式?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個(gè)表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動(dòng)填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱(chēng) ASC)
主站蜘蛛池模板: 国产精品美女久久久久久久网站 | 欧美日韩亚洲在线 | 18gay男同69亚洲网站 | 欧美一级二级三级 | 国产精久久久 | 狠狠操电影 | 美女露尿口视频 | 久久久精品一区二区三区 | 亚欧洲精品在线视频免费观看 | av天天澡天天爽天天av | av在线天堂 | 亚洲精品国产成人 | 日日夜夜影院 | 另类专区亚洲 | 亚洲精品在线视频 | 日韩一级黄色片 | 国产视频观看 | 成人黄色网址大全 | 久久久视 | 精品久久一区 | 成人精品一区二区 | 国产精品一区二区在线免费观看 | 91日韩在线 | 在线观看第一页 | 一区二区三区中文字幕 | 欧美日韩在线视频一区二区 | 欧美专区日韩专区 | 久久免费高清 | 欧美黑人激情 | 日韩成人精品一区 | 久久精品色视频 | 91日日| 韩日一区二区三区 | 91高清在线观看 | 91.色| 免费精品 | 欧美不卡在线 | 麻豆91av | 久久久久久久久久久丰满 | 国产午夜av片 | 亚洲国产精品视频 |