Controller/AppController.php
class AppController extends Controller {
public function beforeFilter() {
$this->Auth->allow('index');
$this->loadModel('Category');
$this->set('categories', $this->Category->find('all', array('order' => 'Category.id ASC')));
}
}
Controller/ProductsController.php
class ProductsController extends AppController {
public function category($category_id = null) {
$file = $this->Product->findAllByCategoryId($category_id);
$id = $file['Product']['id'];
$this->paginate = array('limit' => 10,
'contain' => array('Comment' => array('fields' => array('COUNT(*) As count'))),
'order' => array('Product.id DESC'),
'conditions' => array('Product.category_id' => $category_id, 'Product.is_active' => 'Y'));
$products = $this->Paginate('Product');
$this->set(compact('products'));
}
}
View/Layout/default.ctp
<div id="leftcolumn">
<ul>
<?php foreach ($categories as $category): ?>
<li> <?php echo $this->Html->link(__($category['Category']['category']), array('controller' => 'products', 'action' => 'category', $category['Category']['id'])); ?> </li>
<?php endforeach; ?>
</ul>
</div>
any ideas, suggestions, or hints how to achieve this?
thanks and best regards
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment