这是我扩展 JModelList 的类:
class AkceHnedModelActions extends JModelList
{
public function getItems()
{
$url = '...';
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => TRUE
));
// aby me https fungovalo na localhostu, na serveru potom odstranit
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// Send the request
$getResponse = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($getResponse == FALSE){
die(curl_error($ch));
}
else
{
$results = array();
$jsonObject = json_decode($getResponse, true);
foreach ($jsonObject AS $key => $value) {
$obj = new Action($value);
$results[] = $obj;
}
$this->items = $results;
}
return $this;
}
}
class Action
{
function __construct(array $data) {
foreach($data as $key => $val) {
$this->{$key} = $val;
}
}
}
我试图在 View 的表中为每个对象拥有自己的行。我有这个代码供查看:
<table>
<tbody>
<?php foreach ($this->items as $i => $item): ?>
<tr class="row"><td><?php echo $item->id ?></td>
<td><?php print_r($item) ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
我无法让它工作。我将所有数组放在一行中。如何创建可以分配给项目的列表?