1

I am currently working on a component which will display "events", stored in a database, on a map (filterable by location, category, date etc...). My first step is to display a simple report of the database, in a table. However, I am struggling to populate the html table with the values stored in my sql table. Any ideas where i am going wrong? From what i understand, Joomla requires a model, view, and controller. Here is my code for each:

com_filteredMap/site/models/filteredmap.php

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

/**
 * FilteredMapList Model
 *
 * @since  0.0.1
 */
class FilteredMapModelFilteredMap extends JModelList
{
    /**
     * Method to build an SQL query to load the list data.
     *
     * @return      string  An SQL query
     */
    protected function getListQuery()
    {
        // Initialize variables.
        $db    = JFactory::getDbo();
        $query = $db->getQuery(true);

        // Create the base select statement.
        $query->select('*')
                ->from($db->quoteName('#__filteredmap'));

        return $query;
    }
}

com_filteredMap/site/views/filteredmap/view.html.php

<?php
class FilteredMapViewFilteredMap extends JViewLegacy
{
    /**
     * Display the Filtered map view
     *
     * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
     *
     * @return  void
     */
    function display($tpl = null)
    {
        // Assign data to the view
        $this->item = $this->get('Item');
        $this->pagination   = $this->get('Pagination');

        // Check for errors.
        if (count($errors = $this->get('Errors')))
        {
            JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');

            return false;
        }

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

com_filteredMap/site/controller.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/**
 * Filtered Map Component Controller
 *
 * @since  0.0.1
 */
class FilteredMapController extends JControllerLegacy
{
        /**
     * Proxy for getModel.
     *
     * @param   string  $name    The model name. Optional.
     * @param   string  $prefix  The class prefix. Optional.
     * @param   array   $config  Configuration array for model. Optional.
     *
     * @return  object  The model.
     *
     * @since   1.6
     */
    public function getModel($name = 'FilteredMap', $prefix = 'FilteredMapModel', $config = array('ignore_request' => true))
    {
        $model = parent::getModel($name, $prefix, $config);

        return $model;
    }
}

com_filteredMap/site/views/filteredmap/tmpl/default.php

    <?php

// No direct access to this file
defined('_JEXEC') or die('Restricted access');
?>
<h1> Filtered Map </h1>

<form method="post" id="frontEndForm" name="frontEndForm">
    <table class="table table-striped table-hover">
        <thead>
        <tr>
            <th width="84%">
                <?php echo JText::_('Event Sumary') ;?>
            </th>
            <th width="6%">
                <?php echo JText::_('Date'); ?>
            </th>
            <th width="10%">
                <?php echo JText::_('Location'); ?>            
            </th>
        </tr>
        </thead>
                <tfoot>
            <tr>
                <td colspan="5">
                    <?php //echo $this->pagination->getListFooter(); ?>
                </td>
            </tr>
        </tfoot>
        <tbody>
            <?php if (!empty($this->items)) : ?>
                <?php foreach ($this->items as $i => $row) : ?>
                    <tr>
                        <td>
                            <?php echo $row->title; ?>
                        </td>
                        <td>
                            <?php echo $row->dates; ?>
                        </td>
                        <td>
                            <?php //addlocationhere ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </tbody>
    </table>
</form>

The above code causes the following to be displayed:

screenshot of extension's front end page

I have worked with Joomla for a while but i am fairly new to programming extensions. Any help/advise would be appreciated.

1

Overall this is coming along well!

You just need to change in your view.html.php

$this->item = $this->get('Item');

to

$this->items = $this->get('Items');

This call will get translated by the view get function into a call getItems in the model JModelList, which will then run the query you supplied in your model getListQuery.

You're already iterating through $this->items properly in your layout file.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.