在我的自定义组件中,在站点视图中,我有一个国家列表(视图:国家)。单击一个国家,将显示另一个视图(视图:人员),显示居住在该国家/地区的所有人员。
现在,在个人视图中,我想显示该国的名称和国旗。
所以我想添加function getCountry()
一个...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;
}
然后,我添加到.../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
(...)
结果:我以为我可以在---/site/views/persons/tmpl/default.php
类似...
<h1><?php echo $this->country->name; ?></h1>
<img src="<?php echo $this->country->flag; ?>" />
...但我没有输出...我做错了什么?