I am trying to create a model in Joomla that will display various information pertaining to a certain ID. When I create the function:
public function getItem ($id = null)
{
if ($this->_item === null)
{
$this->_item = false;
if (empty($id))
{
$id = $this->getState('player.id');
}
}
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query = "SELECT name FROM #__baseball_teams WHERE id = $id";
$db->setQuery($query);
$this->_item = $db->loadObject()->name;
return $this->_item;
}
But when I change the query results from:
$this->_item = $db->loadObject()->name;
to
$this->_item->team = $db->loadObject()->name;
I keep getting errors such as Attempt to assign property "team" on bool
Or if I try changing things around, I get Attempt to assign string "team" on null
, etc.
When I run a print_r
, the data is there and a var_dump
shows as strings, but I just have no idea why I cannot assign an additional ->
without getting errors?