MVC Help

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
charltondurie
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Thu Apr 30, 2009 8:42 pm

MVC Help

Post by charltondurie » Wed Dec 22, 2010 8:05 am

Hi Guys,

I have been using Joomla for a long time now but have never looked into component development. I have a little experience with PHP and have just started looking into MVC structure. I am wondering if someone can guide me in the right direction with the code below.

I am simply trying to pull data from the database and display it on the page but I get the following error:

Code: Select all

Notice: Trying to get property of non-object in com_calendar\views\calendar\tmpl\default.php on line 9
com_calendar\models\calendar.php

Code: Select all

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla modelitem library
jimport('joomla.application.component.modelitem');
 
/**
 * Calendar Model
 */
class CalendarModelCalendar extends JModelItem
{
        /**
         * @var string msg
         */
        protected $title;
        
		/**
         * Method to get a list of options for a list input.
         *
         * @return      array           An array of JHtml options.
         */
        function getOptions() 
        {
                $db = JFactory::getDBO();
                $query = $db->getQuery(true);
                $query->select('id,name,location,date,reg_open,reg_close,instructions');
                $query->from('#__calendar');
                $db->setQuery($query);
                $events = $db->loadRowList();

                return $events;
        }
}
com_calendar\views\calendar\view.html.php

Code: Select all

<?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 Calendar Component
 */
class CalendarViewCalendar extends JView
{
// Overwriting JView display method
        function display($tpl = null) 
        {
                // Assign data to the view
                $this->events = $this->get('Options');
 
                // Check for errors.
                if (count($errors = $this->get('Errors'))) 
                {
                        JError::raiseError(500, implode('<br />', $errors));
                        return false;
                }
                // Display the view
                parent::display($tpl);
        }
}
com_calendar\views\calendar\tmpl\default.php

Code: Select all

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
?>
<h1>Calendar</h1>
<?php
foreach($this->events as $event) 
	{
		echo "Name: " . $event->name . "<br>";
	}
?>

charltondurie
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Thu Apr 30, 2009 8:42 pm

Re: MVC Help

Post by charltondurie » Wed Dec 22, 2010 9:15 am

All good. I figured it out thanks anyway.


Locked

Return to “Joomla! 2.5 Coding”