Joomla-create-modules
Joomla-モジュールの作成
この章では、Joomlaでの*モジュールの作成*について学習します。 モジュールは、柔軟で軽量で、ページのレンダリングに役立つ拡張機能です。
モジュールを作成する
以下は、Joomlaでモジュールを作成する簡単な手順です。
ステップ1 *- *Joomla → modules フォルダーに mod_firstmodule というフォルダーを作成します。
ステップ2 *- *mod_firstmodule フォルダーに「helper.php」というファイルを作成します。 このファイルにはヘルパーとしてクラス名が含まれており、取得したデータをモジュール出力に表示するのに役立ちます。
helper.php
<?php
/**
*Helper class for Hello World! module
*
*@package Joomla.Tutorials
* @subpackage Modules
*@link http://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module
* @license GNU/GPL, see LICENSE.php
*mod_helloworld is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
*is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/
class ModHelloWorldHelper {
/**
*Retrieves the hello message
*
*@param array $params An object containing the module parameters
*
*@access public
*/
public static function getHello($params) {
return 'Hello, World!';
}
}
?>
ステップ3 *- *mod_helloworld.php というファイルを作成します。 これは、初期化ルーチンを実行し、必要なデータを収集し、テンプレートを使用してモジュール出力を表示するモジュールのエントリポイントです。
mod_helloworld.php
<?php
/**
*Hello World! Module Entry Point
*
*@package Joomla.Tutorials
* @subpackage Modules
*@license GNU/GPL, see LICENSE.php
* @link http://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module
*mod_helloworld is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
*is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/
//No direct access
defined('_JEXEC') or die;
//Include the syndicate functions only once
require_once dirname(__FILE__) . '/helper.php';
$hello = modHelloWorldHelper::getHello($params);
require JModuleHelper::getLayoutPath('mod_helloworld');
?>
ステップ4 *- mod_helloworld.xmlファイルを作成します*。 このファイルには、モジュールに関する情報が含まれています。 このxmlファイルには、モジュールのJoomlaにインストールされるファイルの情報が含まれています。
mod_helloworld.xmlファイル
<?xml version = "1.0" encoding = "utf-8"?>
<extension type = "module" version = "3.1.0" client = "site" method="upgrade">
<name>Hello, World!</name>
<author>Tutorials Point</author>
<version>1.0.0</version>
<description>A simple Hello World! module.</description>
<files>
<filename>mod_helloworld.xml</filename>
<filename module = "mod_helloworld">mod_helloworld.php</filename>
<filename>indexl</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/indexl</filename>
</files>
<config>
</config>
</extension>
ステップ5 *- *indexl というシンプルなhtmlファイルを作成します。 このファイルを作成する目的は、作成されたディレクトリを参照しないことです。 ユーザーがこれらのディレクトリを参照すると、indexlファイルが表示されます。 このファイルを空にしておくこともできます。
インデックス
<html>
<body> Welcome to Tutorials Point!!!!! </body>
</html>
ステップ6 *- *tmpl という名前のフォルダーを作成します。 以下に示す default.php ファイルとindexl(ステップ(5)で作成)を tmpl フォルダーの下に配置します。 default.phpファイルは、モジュールの出力を表示するテンプレートです。
default.php
<?php
/**
*@package Joomla.Site
* @subpackage mod_firstmodule
*@copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
>
<p>Hello World!!!!!!</p>
これらすべてのファイルの作成が完了したら、完全なフォルダー mod_firstmodule を圧縮します。
ステップ7 *-Joomla管理者の *Extension → Extension Manager に移動すると、次の画面が表示されます。 ここで、作成したモジュールファイルをアップロードしてインストールできます。 mod_firstmodule フォルダー。 * [ファイルを選択]をクリックして、作成されたモジュールファイル(圧縮されたファイル)を選択します。 [アップロードしてインストール]ボタンをクリックして、モジュールファイルをアップロードします。
- ステップ8 *-アップロードとインストール後、*モジュールマネージャー*に移動して、*新規*をクリックします。 ここで、作成したモジュールファイルを次のように表示できます。
- ステップ9 *-このモジュールを他のモジュールと同様に割り当ててから公開できます。