在cakephp视图中的html表行中创建表单

时间:2018-04-26 07:58:46

标签: php html cakephp cakephp-2.7

我想在cakePHP的 foreach循环中的表td中创建表单,我想只在3个表 td 中构建并更新它的工作正常,但由于 td 中的形式,唯一的问题是标题的对齐。如果我从pf td中取出表格,它就无法运作

<table class="table table-hover ">
<thead>
<tr>
    <th>Customer</th>
    <th>Dress</th>
    <th>Order Date</th>
    <th>Delivery Date</th>
    <th>Status</th>
    <th>Tailor</th>
    <th>Tailor Cost</th>
    <th class="actions"><?php echo __('Actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
    <tr>
        <td>
            <?php echo $this->Html->link($order['Customer']['name'], array('controller' => 'customers', 'action' => 'view', $order['Customer']['id'])); ?>
        </td>
        <td>
            <?php echo $this->Html->link($order['Dress']['type'], array('controller' => 'dresses', 'action' => 'view', $order['Dress']['id'])); ?>
        </td>
        <td><?php echo h(date('d-M-y',strtotime($order['Order']['order_date']))); ?>&nbsp;</td>
        <td><?php echo h(date('d-M-y',strtotime($order['Order']['delivery_date']))); ?>&nbsp;</td>
        <td><?php echo h($status[$order['Order']['status']]); ?>&nbsp;</td>
        **<td>
            <?php echo $this->Form->create('Order',['class'=>'form-inline']); ?>
            <?php echo $this->Form->input('id', ['type'=>'hidden','value'=>$order['Order']['id']]); ?>
            <?php echo $this->Form->input('user_id', ['empty'=>'--Select--','options'=>$users, 'selected'=>$order['User']['id'], 'div' => false, 'label' => false, 'class' => 'form-control']); ?>
            <?php echo $this->Form->input('tailor_price', ['value' =>$order['Order']['tailor_price'], 'div' => false, 'label' => false, 'class' => 'form-control','style'=>'max-width:140px;']); ?>
            <?php echo $this->Form->button(__('Update'), ['class' => 'btn btn-default']) ?>
            <?php echo $this->Form->end(); ?>
        </td>**
    </tr>
<?php endforeach; ?>
</tbody>

但它打破了桌面和td路线:

enter image description here

请帮帮我。先谢谢你。

2 个答案:

答案 0 :(得分:0)

试试这个

<?php echo $this->Form->create('Order',['class'=>'form-inline']); ?>
   <td>
            <?php echo $this->Html->link($order['Customer']['name'], array('controller' => 'customers', 'action' => 'view', $order['Customer']['id'])); ?>
        </td>
   <td>
            <?php echo $this->Html->link($order['Dress']['type'], array('controller' => 'dresses', 'action' => 'view', $order['Dress']['id'])); ?>
  </td>
  <td><?php echo h(date('d-M-y',strtotime($order['Order']['order_date']))); ?>&nbsp;</td>
  <td><?php echo h(date('d-M-y',strtotime($order['Order']['delivery_date']))); ?>&nbsp;</td>
        <td><?php echo h($status[$order['Order']['status']]); ?>&nbsp; 
  </td>
  <td>
       <?php echo $this->Form->input('id', ['type'=>'hidden','value'=>$order['Order']['id']]); ?>
       <?php echo $this->Form->input('user_id', ['empty'=>'--Select--','options'=>$users, 'selected'=>$order['User']['id'], 'div' => false, 'label' => false, 'class' => 'form-control']); ?>
   </td>
   <td>
       <?php echo $this->Form->input('tailor_price', ['value' =>$order['Order']['tailor_price'], 'div' => false, 'label' => false, 'class' => 'form-control','style'=>'max-width:140px;']); ?>
   </td>
   <td>
            <?php echo $this->Form->button(__('Update'), ['class' => 'btn btn-default']) ?>          
   </td>
<?php echo $this->Form->end(); ?>

答案 1 :(得分:0)

您的thtd不相等th为8,td仅为6 (这就是你的专栏混合的原因)

<table class="table table-hover ">
<thead>
<tr>
    <th>Customer</th>
    <th>Dress</th>
    <th>Order Date</th>
    <th>Delivery Date</th>
    <th>Status</th>
    <th>Tailor</th>
    <th>Tailor Cost</th>
    <th class="actions"><?php echo __('Actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
    <tr>
        <?php echo $this->Form->create('Order',['class'=>'form-inline']); ?>
        <td>
            <?php echo $this->Html->link($order['Customer']['name'], array('controller' => 'customers', 'action' => 'view', $order['Customer']['id'])); ?>
        </td>
        <td>
            <?php echo $this->Html->link($order['Dress']['type'], array('controller' => 'dresses', 'action' => 'view', $order['Dress']['id'])); ?>
        </td>
        <td><?php echo h(date('d-M-y',strtotime($order['Order']['order_date']))); ?>&nbsp;</td>
        <td><?php echo h(date('d-M-y',strtotime($order['Order']['delivery_date']))); ?>&nbsp;</td>
        <td><?php echo h($status[$order['Order']['status']]); ?>&nbsp;</td>
        <td>
            <?php echo $this->Form->input('id', ['type'=>'hidden','value'=>$order['Order']['id']]); ?>
            <?php echo $this->Form->input('user_id', ['empty'=>'--Select--','options'=>$users, 'selected'=>$order['User']['id'], 'div' => false, 'label' => false, 'class' => 'form-control']); ?>
        </td>
        <td>
            <?php echo $this->Form->input('tailor_price', ['value' =>$order['Order']['tailor_price'], 'div' => false, 'label' => false, 'class' => 'form-control','style'=>'max-width:140px;']); ?>
        </td>   
        <td>
            <?php echo $this->Form->button(__('Update'), ['class' => 'btn btn-default']) ?>
        </td>
        <?php echo $this->Form->end(); ?>
    </tr>
<?php endforeach; ?>
</tbody>