我的网站收到了一条警告信息:
Warning: Creating default object from empty value in /homepages/16/d381040813/htdocs/components/com_events_booking/models/event.php on line 169
我在event.php中打开了第169行,代码为:
$row->event->BeforeDisplay = trim(implode("\n", $results));
我的event.php文件是:
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.model');
/**
* Event_Booking Component - Event Model
* @package Event_Booking
* @subpackage Model
*/
class Events_BookingModelEvent extends JModel {
/** @var int Total of documents */
var $_total = null;
/** @var object Pagination object */
var $_pagination = null;
/** @var string */
var $nullDate = null;
/** @var string */
var $now = null;
/** @var int */
var $_id = null;
/** @var array realty data */
var $_data = null;
/**
* Constructor.
*/
function __construct() {
global $mainframe, $option;
parent::__construct();
$this->nullDate = $this->_db->getNullDate();
$jdate = JFactory::getDate();
$this->now = $jdate->toMySQL();
$id = JRequest::getInt('id', 0);
if( !$id ){
$session = &JFactory::getSession();
$user = JFactory::getUser();
$joinevent = $session->get('joinevent');
if( @count( $joinevent[$user->get('id')] ) ){
$id = $joinevent[$user->get('id')]['id'];
}
}
$this->setId($id);
}
/**
* Method to set the identifier
*
* @access public
* @param int $id realty identifier
*/
function setId($id) {
$this->_id = $id;
$this->_data = null;
}
/**
* Method to get event item data.
* @access public
* @return object
*/
function getData($id = null) {
// Lets load the data if it doesn't already exist
if (empty($this->_data)) {
$id = $id ? $id : $this->_id;
$query = 'SELECT a.*, b.id AS bid , b.title AS btitle , c.id AS cid , c.title AS ctitle, c.street, c.city, c.state, c.zip, ct.name AS `country`, c.website, c.latitude, c.longitude'
. ' FROM #__events_events AS a'
. ' INNER JOIN #__events_categories AS b ON a.category_id = b.id'
. ' INNER JOIN #__events_venues AS c ON a.venue_id = c.id'
. ' LEFT JOIN #__events_countries AS ct ON ct.code LIKE c.country'
. ' WHERE a.published = 1 AND a.id = '. (int) $id
;
$this->_db->setQuery($query);
$this->_data = $this->_db->loadObject();
}
if (!$this->_data->id) {
JError::raiseError( 404, JText::_('COM_EVENTS_BOOKING_EVENT_NOT_FOUND'));
}
return $this->_data;
}
/**
* Method to get group item data.
* @access public
* @return array
*/
function getGroup($id = null) {
$query = 'SELECT g.* FROM #__events_groups as g'
. ' WHERE g.published = 1 AND a.id = '. (int) $id
;
$this->_db->setQuery($query);
$row = $this->_db->loadObject();
return $row;
}
/**
* Method to get Expired item data.
* @access public
* @return array
*/
function getExpired() {
$date = new JDate();
$id = $this->_id;
$query = 'SELECT COUNT(*) FROM #__events_events AS a WHERE a.id = '.(int)$id.' AND a.published = 1 AND a.expired > '.$this->_db->Quote($date->toMySQL());
$this->_db->setQuery($query);
$row = $this->_db->loadResult();
return $row;
}
/**
* Method to get Expired Capacity.
* @access public
* @return array
*/
function getCapacity() {
$data = $this->getData();
$id = $this->_id;
$result = $this->getMemberCapacity($data->capacity);
return $result;
}
/**
* Method to get Member Capacity COM_EVENTS_BOOKING_JOIN_EVENT.
* @access public
* @return array
*/
function getMemberCapacity($capacity=0) {
$id = $this->_id;
// $query = 'SELECT COUNT(*) FROM #__events_members AS a WHERE a.event_id = '.(int)$id;
$query = 'SELECT COUNT(*)'
. ' FROM #__events_members AS a'
. ' INNER JOIN #__events_bookings AS b ON b.id = a.booking_id'
. ' WHERE a.event_id = '.(int)$id
. ' AND b.approved = 1'
. ' AND a.approved = 1'
;
$this->_db->setQuery($query);
$row = $this->_db->loadResult();
$result = array();
$result['m_capacity'] = $row;
$result['e_capacity'] = (int)($capacity-(int)$row);
return $result;
}
function execPlugins(&$row, $view, $task){
$params = &JComponentHelper::getParams('com_events_booking');
$limitstart = JRequest::getInt('limitstart');
//Import plugins
$dispatcher = &JDispatcher::getInstance();
JPluginHelper::importPlugin ('content');
$row->text = $row->description;
$results = $dispatcher->trigger('onBeforeDisplay', array ( 'com_events_booking.event', &$row, &$params, $limitstart));
$row->event->BeforeDisplay = trim(implode("\n", $results));
$results = $dispatcher->trigger('onAfterDisplay', array ( 'com_events_booking.event', &$row, &$params, $limitstart));
$row->event->AfterDisplay = trim(implode("\n", $results));
$results = $dispatcher->trigger('onAfterDisplayTitle', array ( 'com_events_booking.event', &$row, &$params, $limitstart));
$row->event->AfterDisplayTitle = trim(implode("\n", $results));
$results = $dispatcher->trigger('onBeforeDisplayContent', array ( 'com_events_booking.event', &$row, &$params, $limitstart));
$row->event->BeforeDisplayContent = trim(implode("\n", $results));
$results = $dispatcher->trigger('onAfterDisplayContent', array ( 'com_events_booking.event', &$row, &$params, $limitstart));
$row->event->AfterDisplayContent = trim(implode("\n", $results));
$dispatcher->trigger('onContentPrepare', array ( 'com_events_booking.event', &$row, &$params, $limitstart));
return $row;
}
/**
* Method to store the booking
*
* @access public
* @param $data
* @return boolean True on success
*/
function store($data) {
//$row = JTable::getInstance('form', 'Table');
$row =& $this->getTable('event');
// bind the form fields to the version table
if (!$row->bind($data)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// make sure the category is valid
if (!$row->check()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// store the category table to the database
if (!$row->store()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
return $row;
}
我用Google搜索了一天,但没有结果。请帮我隐藏此警告或解决此问题。
答案 0 :(得分:2)
您没有创建$row->event
对象。因此,当您设置$row->event->BeforeDisplay
时,将针对尚未设置的内容创建BeforeDisplay对象。如果您在事件开始运行之前执行$row->event = new stdClass();
之类的操作,则应将其清除。