phpjoomlajoomla3.0joomla-component

Joomla Component: View: Get values from field


I'm new to Joomla, especially to component development. Anyway, here's my question:

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);
    }
}

My question is: How do I access the value from the field[name="galleryFolder"] the user provided in the menu configuration?

Thanks for your help! I really do appreciate it.


Solution

  • This parameter is located in the query variable of the menu item.

    You can try this for example:

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