在目录视图中从rsform回显特定字段

时间:2016-06-03 06:39:40

标签: php joomla get echo

我在积极使用该网站多年后的第一篇文章。

我正在尝试通过公司内部网站点上的RSFORM设置目录视图。一切都已完成,但在目录视图中我想回显表单中一个选择器的值(选择器隐藏在表单中,并在编辑中可见)。因此,当您在表单提交后编辑此选择器时,它会将此值回显到目录的特定区域(将其添加到整行的类)。

但我无法弄清楚如何获得特定的字段值..

我试过这个

echo $this->$field(FIELD_NAME); 

代码部分就像这样

    <?php if ($this->items) { ?>
    <?php foreach ($this->items as $i => $item) { ?>
    <tr class="row<?php echo $i % 2; ?> directoryRow **<?php echo $this->$field(FIELD_NAME);  ?>**">
        <?php if ($this->directory->enablecsv) { ?>
            <td align="center" class="center directoryGrid"><?php echo JHtml::_('grid.id', $i, $item->SubmissionId); ?></td>
        <?php } ?>
        <?php foreach ($this->viewableFields as $field) { ?>
            <td align="center" class="center directoryCol directoryCol<?php echo $this->getFilteredName($field->FieldName); ?>"><?php echo $this->getValue($item, $field); ?></td>
        <?php } ?>

这是来自view.html.php文件

<?php

defined('_JEXEC') or die('Restricted access');

class RSFormViewDirectory extends JViewLegacy
{
    public function display( $tpl = null ) {
        $this->app          = JFactory::getApplication();
        $this->doc          = JFactory::getDocument();
        $this->document     = &$this->doc;
        $this->params       = $this->app->getParams('com_rsform');
        $this->layout       = $this->getLayout();
        $this->directory    = $this->get('Directory');
        $this->tooltipClass = RSFormProHelper::getTooltipClass();

        if ($this->layout == 'view') {
            $this->doc->addStyleSheet(JHtml::stylesheet('com_rsform/directory.css', array(), true, true));

            $this->template = $this->get('template');
            $this->canEdit  = RSFormProHelper::canEdit($this->params->get('formId'),$this->app->input->getInt('id',0));
            $this->id       = $this->app->input->getInt('id',0);

            // Add custom CSS and JS
            if ($this->directory->JS)
                $this->doc->addCustomTag($this->directory->JS);
            if ($this->directory->CSS)
                $this->doc->addCustomTag($this->directory->CSS);

            // Add pathway
            $this->app->getPathway()->addItem(JText::_('RSFP_SUBM_DIR_VIEW'), '');
        } elseif ($this->layout == 'edit') {
            if (RSFormProHelper::canEdit($this->params->get('formId'),$this->app->input->getInt('id',0))) {
                $this->doc->addStyleSheet(JHtml::stylesheet('com_rsform/directory.css', array(), true, true));
                $this->fields       = $this->get('EditFields');
            } else {
                $this->app->redirect(JURI::root());
            }

            // Add pathway
            $this->app->getPathway()->addItem(JText::_('RSFP_SUBM_DIR_EDIT'), '');
        } else {
            $this->search           = $this->get('Search');
            $this->items            = $this->get('Items');
            $this->uploadFields     = $this->get('uploadFields');
            $this->multipleFields   = $this->get('multipleFields');
            $this->unescapedFields  = array_merge($this->multipleFields, $this->uploadFields);
            $this->fields           = $this->get('Fields');
            $this->headers          = RSFormProHelper::getDirectoryStaticHeaders();
            $this->hasDetailFields  = $this->hasDetailFields();
            $this->hasSearchFields  = $this->hasSearchFields();
            $this->viewableFields   = $this->getViewableFields();
            $this->pagination       = $this->get('Pagination');

            $this->filter_search    = $this->get('Search');
            $this->filter_order     = $this->get('ListOrder');
            $this->filter_order_Dir = $this->get('ListDirn');           

            // Add custom CSS and JS
            if ($this->directory->JS)
                $this->doc->addCustomTag($this->directory->JS);
            if ($this->directory->CSS)
                $this->doc->addCustomTag($this->directory->CSS);
        }

        if ($this->params->get('robots')) {
            $this->document->setMetadata('robots', $this->params->get('robots'));
        }

        if ($this->params->get('menu-meta_description')) {
            $this->document->setDescription($this->params->get('menu-meta_description'));
        }

        if ($this->params->get('menu-meta_keywords')) {
            $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
        }

        $title = $this->params->get('page_title', '');
        if (empty($title)) {
            $title = JFactory::getConfig()->get('sitename');
        }
        elseif (JFactory::getConfig()->get('sitename_pagetitles', 0) == 1) {
            $title = JText::sprintf('JPAGETITLE', JFactory::getConfig()->get('sitename'), $title);
        }
        elseif (JFactory::getConfig()->get('sitename_pagetitles', 0) == 2) {
            $title = JText::sprintf('JPAGETITLE', $title, JFactory::getConfig()->get('sitename'));
        }

        $this->document->setTitle($title);

        parent::display($tpl);
    }

    protected function hasDetailFields() {
        foreach ($this->fields as $field) {
            if ($field->indetails) {
                return true;
            }
        }
    }

    protected function hasSearchFields() {
        foreach ($this->fields as $field) {
            if ($field->searchable) {
                return true;
            }
        }
    }

    protected function getViewableFields() {
        $return = array();

        foreach ($this->fields as $field) {
            if ($field->viewable) {
                $return[] = $field;
            }
        }

        return $return;
    }

    protected function getFilteredName($name) {
        return ucfirst(JFilterOutput::stringURLSafe($name));
    }

    protected function getValue($item, $field) {
        if (in_array($field->FieldName, $this->unescapedFields)) {
            return $item->{$field->FieldName};
        } else {
            // Static header?
            if ($field->componentId < 0 && isset($this->headers[$field->componentId])) {
                $header = $this->headers[$field->componentId];
                if ($header == 'DateSubmitted') {
                    $value = RSFormProHelper::getDate($item->$header);
                } else {
                    $value = $item->$header;
                }
            } else {
                // Dynamic header.
                $value = $item->{$field->FieldName};
            }

            return $this->escape($value);
        }
    }

    public function pdfLink($id) {
        $app        = JFactory::getApplication();
        $has_suffix = JFactory::getConfig()->get('sef') && JFactory::getConfig()->get('sef_suffix');
        $pdf_link = JRoute::_('index.php?option=com_rsform&view=directory&layout=view&id='.$id.'&format=pdf');
        if ($has_suffix) {
            $pdf_link .= strpos($pdf_link, '?') === false ? '?' : '&';
            $pdf_link .= 'format=pdf';
        }

        return $pdf_link;
    }
}

0 个答案:

没有答案