I created a simple component with a subform that stores data in a database. Now I need to display this data on the front page. The data is displayed as is from db
{"comment0":{"comment":"one"},"comment1":{"comment":"two"}}
How do I fix it and get values one, two
on front-end? Please tell me step by step.
What I have:
views/myview/tmpl/default.php
<?php defined('_JEXEC') or die; ?>
<?php foreach ($this->items as $item) : ?>
<?php echo $item->comment; ?>
<?php endforeach; ?>
views/myview/view.html.php
<?php defined('_JEXEC') or die;
class MycomponentViewMyView extends JViewLegacy {
protected $items;
public function display($tpl = null)
{
$this->items = $this->get('Items');
$app = JFactory::getApplication();
$params = $app->getParams();
$this->assignRef( 'params', $params );
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode("\n", $errors));
return false;
}
parent::display($tpl);
}
}
also standard model
<?php defined('_JEXEC') or die;
class MyComponentModelMyModel extends JModelList {
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id'
);
}
parent::__construct($config);
}
protected function populateState($ordering = null, $direction = null)
{
$id = JRequest::getInt('id');
$this->setState('id', $id);
}
protected function getListQuery()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select(
$this->getState(
'list.select',
'a.id, a.comment,'
)
);
$query->from($db->quoteName('#__mycomponent').' AS a');
$query->where('(a.state IN (0, 1))');
if ($id = $this->getState('id'))
{
$query->where('a.id = '.(int) $id);
}
return $query;
}
}
echo $item->comment;
is only looping one time and is displaying{"comment0":{"comment":"one"},"comment1":{"comment":"two"}}
? – mickmackusa♦ Jul 6 '18 at 0:21