So what I want is to get all the ordered items grouped by order date on one page, then when I select the date I get all the items for that ordered date. Sounds simple right?
Okay here is my controller:
| CODE |
| function sorted($orderdate_id) { $this->Order->recursive = 0; $this->set('orders', $this->paginate()); $allOrders=$this->Order->find('first', array('fields'=>array('Item.id', 'totalozs', 'Item.name'), 'conditions'=>array('Order.orderdate_id'=>$orderdate_id))); $this->set('orders', $allOrders); } function sort() { $this->Order->recursive = 0; $this->set('orders', $this->paginate()); $allPosts=$this->Order->find('all'); $this->set('orders', $allPosts); } |
| CODE |
| <div class="orders sort"> <h2>Select Order by Date</h2> <!-- Added for pagination --> <?php echo $paginator->counter(array('format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true))); ?></p> <!-- End of Added for pagination --> <table cellpadding="0" cellspacing="0"> <?php $i = 0; foreach ($orders as $order): $class = null; if ($i++ % 2 == 0) { $class = ' class="altrow"'; } ?> <tr<?php echo $class;?>> <td><?php echo $html->link($order['Orderdate']['date'], array('controller'=>'orders', 'action' => 'sorted', $order['Order']['orderdate_id'])); ?></td> </tr> <?php endforeach; ?> </table> |
| CODE |
| <!-- Added for pagination --> <?php echo $paginator->counter(array('format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true))); ?> <!-- End of Added for pagination --> <table cellpadding="0" cellspacing="0"> <?php // echo ("<pre>"); echo print_r($orders); echo("</pre>"); $i = 0; foreach ($orders as $orderss): $class = null; if ($i++ % 2 == 0) { $class = ' class="altrow"'; ?> <tr<?php echo $class; ?>> <td> <?php echo $orders ['Item']['name']; ?></td> <td> <?php echo $orders ['Item']['id']; ?></td> <td> <?php echo $orders ['Order']['totalozs']; }?></td> </tr> <?php endforeach; ?> </table> |
| CODE |
| <?php class Order extends AppModel { var $name = 'Order'; //The Associations below have been created with all possible keys, those that are not needed can be removed var $belongsTo = array( 'Orderdate' => array( 'className' => 'Orderdate', 'foreignKey' => 'orderdate_id', 'conditions' => '', 'fields' => '', 'order' => '' ), 'Customer' => array( 'className' => 'Customer', 'foreignKey' => 'customer_id', 'conditions' => '', 'fields' => '', 'order' => '' ), 'Category' => array( 'className' => 'Category', 'foreignKey' => 'category_id', 'conditions' => '', 'fields' => '', 'order' => '' ), 'Item' => array( 'className' => 'Item', 'foreignKey' => 'item_id', 'conditions' => '', 'fields' => '', 'order' => '' ), 'Purveyor' => array( 'className' => 'Purveyor', 'foreignKey' => 'purveyor_id', 'conditions' => '', 'fields' => '', 'order' => '' ) ); } ?> |