Limit amount of results in CakePHP

1

I'm learning CakePHP and this doubt came to me, if I want to put my limit so that it has start and long range, what would it be like?

$posts = $this->Post->find('all',
                array('conditions' => array(
                    'post_visible !=' => '0'
                    ),
                'limit' => '0,10', 
                'order' => 'id'
                )       
            );

Currently I have it like that but the limit puts it as 0.

I tried it this way: 'limit' => '0'.','.'10' .

    
asked by PardusNIx 14.09.2017 в 17:03
source

2 answers

1

Only the limit is established. And by default you order by id, this would not be necessary.

Try it like this:

$post = $this->Post->find('all')
->where(['post_visible !=' => '0'])
->limit('10');  

Here you have the documentation of Cake, read without fear, you will be understanding!

link

Greetings!

    
answered by 06.10.2017 в 20:44
1

The limit only receives a value not a range, if what you need is page use the method paginate() of the framework you pass as a parameter of how many records you will page

$posts = $this->Post->find('all',
        array('conditions' => array(
            'post_visible !=' => '0'
            ),
        'limit' => 10, 
        'order' => 'id'
        )       
    );

If you need it for something else you can do the find all search then go through the records of 1-10 and perform the logic you need with these records. You can receive in your for these variables of ranges and you already pass them from where you want and you are modifying them.

    
answered by 06.09.2018 в 19:07