上松です。
管理画面へのページ追加について、まとめたいと思います。 今回はモジュールの追加と管理画面のメニュー追加についてです。
・モジュールの追加
ルート | app | |→ code | | |→ community | | |→ core | | |→ local | | | |→ Others | | | | |→ Another | | | | | |→ etc | | | | | | |→ adminhtml.xml | | | | | | |→ config.xml | | ・・・ | |→ etc | |→ modules | | |→ Ohters_Another.xml
モジュールの定義
app/etc/Others_Another.xmlに、モジュールを定義します。
<?xml version="1.0"?>
<config>
<modules>
<Others_Another> ・・・ モジュール
<active>true</active> ・・・ 有効/無効
<codePool>local</codePool> ・・・ コードの場所
</Othres_Another>
</modules>
</config>
<active>がfalseに設定されていればモジュールは読み込まれません。 モジュールがエクステンションだった場合、<codePool>はcommunityになります。
・管理画面へのメニュー追加
管理画面のトップメニューに項目を追加する場合、adminhtml.xmlかconfig.xmlに メニューを定義します。
<?xml version="1.0"?>
<config>
<menu>
<others translate="title" module="others_another"> ・・・ メニュー名
<title>OthersSample</title> ・・・表示するタイトル
<sort_order>120</sort_order> ・・・ 表示順
<children> ・・・サブメニュー
<example translate="title" module="others_another">
・・・ サブメニュー名
<title>Example</title> ・・・ 表示するタイトル
<sort_order>1</sort_order> ・・・表示順
<action>adminhtml/example/index</action>
・・・選択された際に呼ばれるコントローラとアクションメソッド
</example>
</children>
</others>
</menu>
</config>
※ <action>のindexは省略可能です。
※ config.xmlに定義する場合は<adminhtml>で囲む必要があります。
メニュー名のtranslateとmoduleは省略しても表示はされますが、翻訳はされません。
翻訳する場合はモジュールのhelperクラスを用意する必要があります。
class Others_Another_Helper_Data extends Mage_Core_Helper_Abstract {
}
app/code/local/Others/Another/etc/config.xml
<config>
....
<global>
<helpers>
<others_another_hp>
<class>Others_Another_Helper</class>
</others_another_hp>
</helpers>
</global>
....
ここまで設定すればメニューが表示されるようになりますが、サブメニューを選択しても
404エラーとなってページは表示されません。
次回はページの表示についてまとめたいと思います。