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