0

Hello I m creating simple blog site here view blog at landing page but if user choose any category the blog under this category only listed . My problem is when user select category from right sidebar it return all table records. When i print the query it return :

array(
    'log' => array(
        (int) 0 => array(
            'query' => 'SELECT `Category`.`category_id`, `Category`.`name` FROM `cakeBlog`.`categories` AS `Category`   WHERE 1 = 1',
            'params' => array(),
            'affected' => (int) 13,
            'numRows' => (int) 13,
            'took' => (float) 0
        ),
        (int) 1 => array(
            'query' => 'SELECT `Post`.`id`, `Post`.`category_id`, `Post`.`title`, `Post`.`body`, `Post`.`created`, `Post`.`modified`, `Post`.`user_id` FROM `cakeBlog`.`posts` AS `Post`   WHERE 1 = 1    LIMIT 20',
            'params' => array(),
            'affected' => (int) 13,
            'numRows' => (int) 13,
            'took' => (float) 0
        )
    ),
    'count' => (int) 2,
    'time' => (float) 0
)

Here is my controller file PostsController.php

In index function I will check whether category id exist or not?

Please help me... Thanks

Rahul Saxena
  • 465
  • 4
  • 15

1 Answers1

0

Use the following block where you want to fetch categories

if(is_null($categoryId)) {
    $this->Paginator->setting = array(
        'limit' =>'10',
        'order' => array('Post.id' =>'Desc')
        /*'conditions' => array(
            'Post.user_id' => AuthComponent::user(id)
        )*/
    );
    $arrPosts = $this->Paginator->paginate('Post');
    $this->set('posts', $arrPosts);
} else {
    $condition = array('Post.category_id' => $categoryId,'limit' =>'10');
    $da = $this->Paginator->setting = array(
        'conditions' => $condition      
        /*'conditions' => array(
        'Post.user_id' => AuthComponent::user(id)
        )*/
    );

    $arrPosts = $this->Paginator->paginate('Post');
    $log = $this->Post->getDataSource()->getLog(false, false); debug($log);
    $this->set('posts', $arrPosts);
}
Supravat Mondal
  • 2,574
  • 2
  • 22
  • 33