magento
モジュール構造
サーチ…
備考
拡張されるべきモジュールが存在する。将来のアップデートを禁止することなくthe app/code/ファイルを変更することはできません。代わりにapp/code/localディレクトリにモジュールを追加します(ローカルディレクトリが存在しない場合は手動で作成する必要がありますが、Magentoのそれ以降のバージョンでは一般的です)。
すべてのモジュール設定ファイルは<config>タグで始まります。新しいモジュールは<modules>タグ内で宣言され<modules> 。 YOUR_COMPANY_HelloWorldという名前のモジュールが呼び出されますので、 <YOUR_COMPANY_HelloWorld>タグが使用されます。ここではバージョンを定義しています(最初の0.0.1)
XMLイベントのリストは、 http : //www.magentocommerce.com/wiki/5_-_modules_and_development/reference/module_config.xmlにあります。
何か問題があればチェックしてください : http : //coding.smashingmagazine.com/2012/11/30/introducing-magento-layout/
最初からモジュールを作成する(Hello World)
Magentoカスタムモジュール開発は、Magento開発プロジェクトまたはMagentoプロジェクトの中核部分です。既存のMagentoプロジェクトに独自の機能/モジュールを統合したい場合があるためです。
開発者が最初に無効にすべきことは、システムキャッシュです。それ以外の場合は、変更がフラッシュを必要とするため、開発は苦痛になるでしょう。 Magento管理パネルから: System > Cache Management > Select All > Actions : Disable.ナビゲートしSystem > Cache Management > Select All > Actions : Disable.新しいモジュールを作成するには、次のガイドを使用します。
app/code/local/フォルダを作成する - 命名規則は通常、会社の名前(app/code/local/<YOUR_COMPANY>。今私たちのモジュール用のカスタムロケーションがあります。別のディレクトリを作成し、作成するモジュールのタイプに関連するものを呼び出します。例えば、app / code / local / <YOUR_COMPANY> / HelloWorld / - "HelloWorld"は私がこのモジュールと呼ぶものです。
Magentoが新しいモジュールとして認識するように、このディレクトリには
config.xmlが必要です。etcという別のフォルダを作成します。 config.xmlと呼ばれるxmlファイルが続きます。ディレクトリはapp/code/local/<YOUR_COMPANY/HelloWorld/etc/config.xmlこれはxmlファイルの構造です:<?xml version="1.0" encoding="UTF-8" ?> <config> <modules> <YOUR_COMPANY_HelloWorld> <version>0.0.1</version> </YOUR_COMPANY_HelloWorld> </modules> </config>次に、モジュールをMagentoに宣言する必要があります。
app/etc/modules進みapp/etc/modules。私の場合、別のXML文書を作成し、タグの名前をYOUR_COMPANY_HelloWorldに選択します。この文書では、<?xml version="1.0" encoding="UTF-8"?> <config> <modules> <YOUR_COMPANY_HelloWorld> <!-- Whether our module is active: true or false --> <active>true</active> <!-- Which code pool to use: core, community or local --> <codePool>local</codePool> </YOUR_COMPANY_HelloWorld> </modules> </config>再度configとmoduleタグはMagentoに新しいモジュールを宣言するために使用されます。アクティブ
Admin Panel under System > Configuration > Advanced、Admin Panel under System > Configuration > Advancedアクセスできるデフォルト値です。codePoolMagentoのは、どのディレクトリで探すように指示します。local我々の場合にはこのモジュールが設定され、MVC構造のモデルになりました。管理パネルの[
System > Configuration > Advancedで、新しいモジュールを確認できるはずです。 しかし、まだ何もしていません! config.xmlファイルに戻り、XML要素を定義する必要があります。チュートリアルに続きます。これらのXML要素のいくつかを使用して、クラスを作成し、サイトのフロントエンドにあるすべてのページを操作します。
config.xmlファイルに戻って、</modules>タグの下に次のように記述します。<global> <!-- adding a new block definition --> <blocks> <!-- A unique short name for our block files --> <helloworld> <!-- the location of our modules block --> <class>YOUR_COMPANY_HelloWorld_Block</class> </helloworld> </blocks> </global> <!-- We are making changes to the frontend --> <frontend> <!-- We are making changes to the layout of the front end --> <layout> <!-- we are adding a new update file --> <updates> <!-- Creating the name of our update and linking it the module --> <helloworld module="YOUR_COMPANY_HelloWorld"> <!-- The name of the layout file we are adding --> <file>helloworld.xml</file> </helloworld> </updates> </layout> </frontend>ご覧のように、私たちはコアファイルを操作するのではなく、常に拡張しています。
helloworldタグは小文字ですが、これはハンドルを指しているため、継続性のためにできるだけ近い名前を付けます。これをYOUR_COMPANY_HelloWorldモジュールにリンクします。私たちはレイアウトを変更しています。したがって、このハンドルをレイアウトディレクトリに作成する必要があります。
app/design/frontend/base/default/layout進みapp/design/frontend/base/default/layout。私たちはhelloworld.xmlファイルを探すようモジュールに指示しました。したがって、このディレクトリに作成する必要があります。あなたは何を待っていますか?やれ!それを次のもので埋める:<?xml version="1.0" encoding="UTF-8"?> <!-- All Layout files begin with this code --> <layout> <!-- this is the layout handle. Default is handled on all pages. We want this module to execute on all pages --> <default> <!-- This is the block we want to bolt onto the existing before_body_end block --> <reference name="before_body_end"> <!-- We define our new block and template to be added to before_body_end --> <block name="helloworld_footer" template="helloworld/footer.phtml" type="helloworld/footer"/> </reference> </default> </layout>Magentoの経験が少ない、またはMagentoのチュートリアルを読んだことのある人は、Magentoのコアファイルが存在する場所であるため、ベース/デフォルトで変更を加えていることに気をつけているかもしれません。ただし、ここではファイルを変更していません。新しいファイルを作成しています。さらに、ファイル名の先頭に「helloworld」を付けるので、他のモジュールと競合する可能性はほとんどなく、Magentoをアップグレードする際に問題が発生する可能性はほとんどありません。未来。幸せな日々!
すべてのページに影響を与えたいので、デフォルトタグを使用して
before_body_end構造ブロックを参照します。これはアクションの役割を果たし、MVC構造のビューセクションを起動します。今、私たちは
before_body_endブロックを利用していることを理解しています。それをカスタムブロックにリンクします。これは参照と呼ばれ、 フックです。現在のところ、既存のものにフックしているわけではないので、必要なファイルを作成する必要があります。helloworld.xmlでは、テンプレート内にfooter.phtmlというfooter.phtml。app/design/frontend/base/default/template進み、ディレクトリhelloworldを作成します。このディレクトリの中に
footer.phtmlファイルを作成し、HTMLで記入してください。このチュートリアルでは、PHTMLファイルにリンクされたPHP機能を表示するためにこれを書いています。<p>Hello Everyone! Todays date is <?php echo $this->getDate() ?></p>テンプレートとブロック機能を結合する独自のブロックオブジェクトを作成する必要があります。ディレクトリapp / code / local / YOUR_COMPANY / HelloWorld / Block /を作成し、この中に
Footer.phpファイルを作成します。これは、 "helloworld / footer"タイプのzeta_layout.xmlで参照されていました。このファイルには、<?php class YOUR_COMPANY_HelloWorld_Block_Footer extends Mage_Core_Block_Template { public function getDate() { $date = date('Y-m-d'); return urlencode($date); } } ?>これは、私たちが
.phtmlファイルから呼び出したgetDate()呼び出しを.phtmlです。Mage_Core_Block_Templateを拡張しMage_Core_Block_Template。これでこの機能は完了です。これをテストするには、各ページのフッターにあなたのモジュールが表示されるはずのホームページに行ってください!