In my custom component, in site view, I have a list of countries (view: countries). Clicking on a country, another view is displayed (view: persons) showing all persons living in that country.
Now, in persons view, I want to display the country's name and flag.
So I want to add a function getCountry()
in ...site/models/persons.php
:
public function getCountry() {
$db = $this->getDBO();
$id = $this->state->get("filter.country");
$sql = "SELECT * FROM #__cnlp_persons_country WHERE id = $id";
$db->setQuery($sql);
$country = $db->loadResult();
// var_dump($country);
return $country;
}
Then, I added to .../site/views/persons/view.html.php
:
class Cnlp_personsViewPersons extends JView
{
protected $items;
protected $state;
protected $params;
protected $country; // <--- I added this
...
public function display($tpl = null)
{
$app = JFactory::getApplication();
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->params = $app->getParams('com_cnlp_trainers');
$this->country = $this->get('Country'); // <--- I added this
(...)
Result: I thought I could then in ---/site/views/persons/tmpl/default.php
something like...
<h1><?php echo $this->country->name; ?></h1>
<img src="<?php echo $this->country->flag; ?>" />
...but I get no output... What did I do wrong?