在我的自定义组件中,在站点视图中,我有一个国家列表(视图:国家)。单击某个国家,将显示另一个视图(视图:人),显示居住在该国家的所有人。
现在,在个人视图中,我想显示国家的名称和国旗。
所以我想添加一个
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; ?>" />
…但我明白
无输出
...
我做错了什么?