Joomla 组件:视图:从字段中获取值

Joomla Component: View: Get values from field

我是 Joomla 的新手,尤其是组件开发。不管怎样,这是我的问题:

site\views\plaingallery\tmpl\default.xml

<?xml version="1.0" encoding="utf-8"?>
<metadata>
    <layout title="COM_PLAINGALLERY_PLAINGALLERY_VIEW_DEFAULT_TITLE">
        <message>
            <![CDATA[COM_PLAINGALLERY_PLAINGALLERY_VIEW_DEFAULT_DESC]]>
        </message>
    </layout>
    <fields name="request"
        addfieldpath="/administrator/components/com_plaingallery/models/fields">
        <fieldset name="request">
            <field name="galleryFolder" type="folderlist" default="" recursive="true"
                label="Select a folder" directory="images" filter="" exclude="" width="300"
                hide_none="true" hide_default="true" stripext="" />
        </fieldset>
    </fields>
</metadata>

site\views\plaingallery\view.html.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

/**
 * HTML View class for the PlainGallery Component
 */
class PlainGalleryViewPlainGallery extends JViewLegacy
{
    // Overwriting JView display method
    function display($tpl = null)
    {
        // Assign data to the view      
        $this->msg = 'I am new to Joomla';

        // Display the view
        parent::display($tpl);
    }
}

我的问题是:如何访问用户在菜单配置中提供的字段[name="galleryFolder"]中的值?

感谢您的帮助!我真的很感激。

该参数位于菜单项的查询变量中。

你可以试试这个,例如:

    $app = JFactory::getApplication();

    /* Default Page fallback*/
    $active = $app->getMenu()->getActive();
    if (NULL == $active) {
        $active = $app->getMenu()->getDefault();
    }

    if ( isset($active->query['galleryFolder']) ) {
        $galleryFolder = $active->query['galleryFolder'];
    }