我坚持使用以下代码:
<?php if ($orders) { ?>
<?php foreach ($orders as $order) { ?>
<tr>
<td style="text-align: center;"><?php if ($order['selected']) { ?>
<input type="checkbox" name="selected[]" value="<?php echo $order['order_id']; ?>" checked="checked" class="trigger"/>
<?php } else { ?>
<input type="checkbox" name="selected[]" value="<?php echo $order['order_id']; ?>" class="trigger" />
<?php } ?></td>
<td class="right"><?php echo $order['order_id']; ?></td>
<td class="left"><?php echo $order['customer']; ?></td>
<td class="left"><?php echo $order['status']; ?></td>
<td class="right"><?php echo $order['total']; ?></td>
<td class="left"><?php echo $order['date_added']; ?></td>
<td class="left"><?php echo $order['date_modified']; ?></td>
<td class="right"><?php foreach ($order['action'] as $action) { ?>
[ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
<?php } ?></td>
</tr>
<tr class="eph-row" style="" >
<td colspan="8" style="background-color: #EBF6FF; height: 50px;">
<div style="">
<label for="eph-dobierka" style="display: table-row;">Dobierka</label>
<input type="text" name="eph-dobierka" id="eph-dobierka" value="" size="7" placeholder="Dobierka"/>
</div>
</td>
</tr>
<?php } ?>
<?php } else { ?>
这是控制器的代码:
public function eph() {
$this->load->model('sale/order');
$this->data['orders'] = array();
$orders = array();
if (isset($this->request->post['selected'])) {
$orders = $this->request->post['selected'];
} elseif (isset($this->request->get['order_id'])) {
$orders[] = $this->request->get['order_id'];
}
$xml = "<?xml version='1.0'?>";
$xml .= "<EPH>\n";
$xml .= "<Zasielky>\n";
foreach ($orders as $order_id) {
$order_info = $this->model_sale_order->getOrder($order_id);
$xml .= "<Zasielka>\n";
$xml .= "<Adresat>\n";
$xml .= "<Meno>".$order_info['shipping_firstname']." ".$order_info['shipping_lastname']."</Meno>\n";
$xml .= "<Organizacia>".$order_info['shipping_company']."</Organizacia>\n";
$xml .= "<Ulica>".$order_info['shipping_address_1']."</Ulica>\n";
$xml .= "<Mesto>".$order_info['shipping_city']."</Mesto>\n";
$xml .= "<PSC>".$order_info['shipping_postcode']."</PSC>\n";
$xml .= "<Telefon>".$order_info['telephone']."</Telefon>\n";
$xml .= "<Email>".$order_info['email']."</Email>\n";
$xml .= "<sum>".$this->request->post['eph-dobierka']."</sum>\n";
$xml .= "</Adresat>\n";
$xml .= "</Zasielka>\n";
}
$xml .= "</Zasielky>\n";
$xml .= "</EPH>\n";
libxml_use_internal_errors(true);
$xmls = simplexml_load_string($xml);
if ($xmls === false) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
Header('Content-type: text/xml');
//Header('Content-disposition: attachment; filename="eph.xml"');
print($xmls->asXML());
}
如您所见,根据 selected[] 值从数据库中查询所选行。
我将<tr class="eph-row">...</tr>
部分添加到原始代码中,我想将一些值传递给控制器,根据选择的行=>:$xml .= "<sum>".$this->request->post['eph-dobierka']."</sum>\n";
在控制器的“order foreach”中(这不起作用)。