1

Joomla 1.6 の任意のページにアクセスするための統合モジュールを作成しています。(API から) カスタム データを基本設定部分に取得するための助けが必要ですが、それを取得する方法が見つからないようです。

モジュールの作成に関するドキュメントを見ると、モジュールの設定が XML 形式で設定されています。そのため、動的オプションをまったく使用せずに、値や選択をハードコーディングする必要があります。基本的に私がやりたいことは、次の 3 つの基本的なプロパティを取る非常に基本的なモジュールをセットアップすることです: URL (API へのパスを定義するために使用) API キー (API キー) リストの選択 (API に接続し、アカウントからリスト名を取得します) .)

リストの選択は、ユーザーの API キーごとに自然に変化しますが、XML ファイルを使用してモジュールをセットアップするため、リストの選択オプションのハードコーディングを回避する方法はありません。

<select>Joomla 1.6 モジュールでオプションを使用してダイナミックを構築できるかどうか教えてください。

注: Joomla での 1.5 と 1.6 の開発には大きな違いがあるため、1.6 と言います。

4

2 に答える 2

4

大変な苦労の末、ここでは何の助けもありません。私はついにそれを成し遂げたと言うことができます。今後のグーグルのプロセスは次のとおりです。

動的なドロップダウンを構築するには、Joomlaが最終的にまとめるために、たくさんのことを正しく行う必要があります。

また、ドキュメントを注意深く読むことを忘れないでください。この回答のメソッドは含まれていませんが、誰かが目を覚ましていつかそこに置くかもしれません。

したがって、1.6アーキテクチャがXMLビルドファイルを使用してモジュール変数をどのようにまとめるかを調べた後、ここに進みます。

XMLは次のようになります。

<?xml version="1.0" encoding="UTF-8"?>
<extension type="module" version="1.6.0" client="site">
    <name>...</name>
    <author>...</author>
    <creationDate>April 2011</creationDate>
    <copyright>Copyright (C) 2011 ... All rights reserved.</copyright>
    <license>GNU General Public License version 2 or later; see LICENSE.txt</license>
    <authorEmail>...</authorEmail>
    <authorUrl>...</authorUrl>
    <version>1.6.0</version>
    <description>
        ...
    </description>
    <files>
        <filename module="mod_your_mod">mod_your_mod.php</filename>
        <filename>helper.php</filename>
        <filename>index.html</filename>
        <folder>tmpl</folder>
        <folder>elements</folder>
        <folder>lib</folder>
    </files>
    <languages />
    <help />
    <config>
        <fields name="params">
            <fieldset name="basic">
                <!-- Custom field, list selection from API -->
                <!-- Path to module external parameters -->
                <field addfieldpath="/modules/mod_your_mod/elements" 
                    name="mod_your_mod_id_selection" <!-- Name of variable -->
                    type="lists" <!-- New variable type -->
                    default="" 
                    label="Select lists" 
                    description="This is the list selection, where you select the list a contact can subscribe to." />
            </fieldset>
            <fieldset
                name="advanced">
                <field
                    name="layout"
                    type="modulelayout"
                    label="JFIELD_ALT_LAYOUT_LABEL"
                    description="JFIELD_ALT_MODULE_LAYOUT_DESC" />
                <field
                    name="moduleclass_sfx"
                    type="text"
                    label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL"
                    description="COM_MODULES_FIELD_MODULECLASS_SFX_DESC" />
                <field
                    name="cache"
                    type="list"
                    default="1"
                    label="COM_MODULES_FIELD_CACHING_LABEL"
                    description="COM_MODULES_FIELD_CACHING_DESC">
                    <option
                        value="1">JGLOBAL_USE_GLOBAL</option>
                    <option
                        value="0">COM_MODULES_FIELD_VALUE_NOCACHING</option>
                </field>
                <field
                    name="cache_time"
                    type="text"
                    default="900"
                    label="COM_MODULES_FIELD_CACHE_TIME_LABEL"
                    description="COM_MODULES_FIELD_CACHE_TIME_DESC" />
                <field
                    name="cachemode"
                    type="hidden"
                    default="itemid">
                    <option value="itemid"></option>
                </field>
            </fieldset>
        </fields>
    </config>
</extension>

したがって、ここここでモジュールを実装するJoomlaの方法に従った後、新しいパラメーター変数タイプをelementsとしてフォルダーに追加しましlists.phpた。名前がXMLファイルで宣言したタイプと同じであることを確認してください。

このファイル内のクラスは次のようになります。

<?php
// No direct access
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
jimport('joomla.html.html');
//import the necessary class definition for formfield
jimport('joomla.form.formfield');

// Include API utility file
require_once(dirname(__FILE__) . '/../lib/your_api.php');

class JFormFieldLists extends JFormField
{
    /**
     * The form field type.
     *
     * @var  string
     * @since 1.6
     */
    protected $type = 'lists'; //the form field type see the name is the same

    /**
     * Method to retrieve the lists that resides in your application using the API.
     *
     * @return array The field option objects.
     * @since 1.6
     */
    protected function getInput()
    {
        $options = array();
        $attr = '';

        $attr .= ' multiple="multiple"';
        $attr .= ' style="width:220px;height:220px;"';

        // Get the database instance
        $db = JFactory::getDbo();
        // Build the select query
        $query = 'SELECT params FROM jos_modules'
            . ' WHERE module="mod_your_mod"';
        $db->setQuery($query);
        $params = $db->loadObjectList();

        // Decode the options to get thje api key and url
        $options = json_decode($params[0]->params, true);

        // Gracefully catch empty fields
        if ( empty($options['api_key']) === true )
        {
            $tmp = JHtml::_(
                'select.option',
                0,
                'No lists available, please add an API key'
            );

            $lists[] = $tmp;

            // The dropdown output, return empty list if no API key specified
            return JHTML::_(
                'select.genericlist',
                $lists,
                $this->name,
                trim($attr),
                'value',
                'text',
                $this->value,
                $this->id
            );
        }
        if ( empty($options['url']) === true )
        {
            $tmp = JHtml::_(
                'select.option',
                0,
                'No lists available, please add the enterprise URL'
            );

            $lists[] = $tmp;

            // The dropdown output, return empty list if no API key specified
            return JHTML::_(
                'select.genericlist',
                $lists,
                $this->name,
                trim($attr),
                'value',
                'text',
                $this->value,
                $this->id
            );

        }

        // Create a new API utility class
        $api = new APIClass(
            $options['url'],
            $options['api_key']
        );

        try
        {
            // Get the lists needed for subscription
            $response = $api->getLists();
        }
        catch ( Exception $e )
        {
            $tmp = JHtml::_(
                'select.option',
                0,
                'Could not connect to the API'
            );

            $lists[] = $tmp;

            // The dropdown output, return empty list if no API key specified
            return JHTML::_(
                'select.genericlist',
                $lists,
                $this->name,
                trim($attr),
                'value',
                'text',
                $this->value,
                $this->id
            );
        }

        $lists = array();

        // Builds the options for the dropdown
        foreach ( $response['data'] as $list )
        {
            // Build options object here
            $tmp = JHtml::_(
                'select.option',
                $list['list_id'],
                $list['list_name']
            );

            $lists[] = $tmp;
        }

        // The dropdown output

        /* The name of the select box MUST be the same as in the XML file otherwise 
         * saving your selection using Joomla will NOT work. Also if you want to make it 
         * multiple selects don't forget the [].
         */
        return JHTML::_(
            'select.genericlist',
            $lists,
            'jform[params][mod_your_mod_id_selection][]',
            trim($attr),
            'value',
            'text',
            $this->value,
            $this->id
        );

    }

}

?>

APIによって構築されたドロップダウンリストの選択(したがって完全に動的)により、次を呼び出すことで簡単に取得できる選択ボックスの名前がモジュールデータベースエントリに保存されるため、すべてが機能していることがわかります。

$api_key = $params->get('api_key', '');

モジュールファイル内。この場合、それはと呼ばれmod_your_mod.phpます。

これが、Joomla1.6モジュールのバックエンドでカスタマイズされたパラメーターを定義するときに役立つことを本当に願っています。これにより、極端なカスタマイズが可能になり、使用したいアプリケーションのAPIと緊密に統合されます。

唯一の欠点は、処理が遅くなる可能性があることですが、APIがダウンしているか、データを正しくプルスルーしていない場合、一連のチェックを使用すると正常に失敗します。全体として、非常に不快なCMSを使用しますが、それは私の意見にすぎません。

于 2011-06-06T10:49:52.600 に答える
3

あなたのニーズが基本的なものであれば、もっと簡単な解決策もあります: http://docs.joomla.org/SQL_form_field_type

「sql」フォーム フィールド タイプがあります。

<field name="title" type="sql" default="10" label="Select an article" query="SELECT id AS value, title FROM #__content" />

(私はあなたの不満に同情します - ドキュメントはひどく、散らばっていて、見つけるのが難しいです)

于 2011-09-30T15:45:34.190 に答える