The view asks the model for the item. In the model, you need the id of the item for querying the database. You can get this id from the Joomla system URL and store it as a state variable in the populateState(). You can also load the global parameters in the state variable. Then, you can use this id in the getItem() to query the database to get the required item.

Step 1: View File

site/views/helloworld/view.html.php

class HelloWorldViewHelloWorld extends JViewLegacy
{

function display($tpl = null)
{
// Assign data to the view
$this->item = $this->get('Item');

// 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);
}
}

Step 2: Model File

site/models/helloworld.php

class HelloWorldModelHelloWorld extends JModelItem
{

protected $item;

protected function populateState()
{
// Get the message id
$jinput = JFactory::getApplication()->input;
$id = $jinput->get('id', 1, 'INT');
$this->setState('message.id', $id);

// Load the parameters.
$this->setState('params', JFactory::getApplication()->getParams());
parent::populateState();
}

public function getItem()
{
if (!isset($this->item))
{
$id = $this->getState('message.id');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('h.greeting, h.params, c.title as category')
->from('#__helloworld as h')
->leftJoin('#__categories as c ON h.catid=c.id')
->where('h.id=' . (int)$id);
$db->setQuery((string)$query);

if ($this->item = $db->loadObject())
{
// Load the JSON string
$params = new JRegistry;
$params->loadString($this->item->params, 'JSON');
$this->item->params = $params;

// Merge global params with item params
$params = clone $this->getState('params');
$params->merge($this->item->params);
$this->item->params = $params;
}
}
return $this->item;
}
}

Step 3: Layout File

The layout can now display the item.

site/views/helloworld/tmpl/default.php

<h3><?php echo $this->item->greeting ; ?></h3>