Cakephp 1.3.

I searched high and low and tried to use several different solutions, and I cannot get it to work. I mainly have products and categories. Categories belong to and belong to many products, as well as HABTM product categories. They are obviously associated in the products_categories join table with the fields id, product_id, category_id.

After all the viewed and processed models of bake models are eaten, some categories and products are added, and their relationships are established. I can go to a page with a specific category of categories, and products related to this category will be displayed in the preview view.

However, there are quite a few products (and there will be more), and I'm struggling to develop how to break up all this related data. It is not possible to simply list all products in a category (maybe 100 or more) Can anyone help? It seems that there are quite a few unanswered questions on this and various various solutions, none of which I can get to work! Please, help!

+3
source share
2 answers

CakePHP controllers have built-in pagination . The documentation is thorough, so I would recommend reading this first. Subsequently, I would be happy to answer any of your questions on this issue.

, , :

class CategoryController extends AppController {
    var $paginate = array(
        'Product' => array(
            'joins' => array(
                array(
                    'table' => 'categories_products', // or products_categories
                    'alias' => 'CatFilter',
                    'type' => 'INNER',
                    'conditions' => array(
                        'CatFilter.product_id = Product.id'
                    )
                )
            ),
            'limit' => 10
         )
    );

    function view ($category_id) {
        $this->set(
            'products', $this->paginate(
                $this->Category->Product, array(
                    'CatFilter.category_id' => $category_id
                )
             )
        );
    }
}
+3

Source: https://habr.com/ru/post/1784106/


All Articles