Joomla组件:查看:从字段

时间:2017-10-22 16:42:16

标签: php joomla joomla3.0 joomla-component

我是Joomla的新手,尤其是组件开发。无论如何,这是我的问题:

网站\视图\ 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>

网站\视图\ 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”]字段中访问该值?

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

1 个答案:

答案 0 :(得分:2)

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

您可以尝试这样做:

    $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'];
    }