Pagination - memory exhausted

In my search model I am allowing the user to select the pagination to use by doing

$dataProvider->pagination->pageSize = $pageSize;

which works, but if they select ALL without applying a filter then then get

“Allowed memory size of 268435456 bytes exhausted (tried to allocate 45 bytes)”

which make perfect sense and I wouldn’t expect Yii or any other language to manage to load everything.

My question is, is there a way to trap this error and in such cases set $pageSize = 20.

Basically, if you can’t do it, default back to 20.

Just thought of something, in the search, is there a way to know if params where supplied? If so, then I could simply default it based on no params being supplied, this would work for my current needs.

That said, if there is a more general, more elegant, way to handle the memory exhausted I’d love to learn.

Thank you.

Sure. Right where you’re setting pagesize:

if (empty($pageSize) || $pageSize > 100) {
    $pageSize = 20;
$dataProvider->pagination->pageSize = $pageSize;

I’m sorry, I should have explained the “select ALL without applying a filter”, when in fact the select All passes a value of 0. So it is always set.

Is there a way to know how many rows are returned and adjust then? say NumRows > 150 then redefine pageSize = 20?

Please ignore, the question. I’ve over-complicated things for no reason. I am simply removing the ALL -> 0 and going to have set value which guarantees pagination in that case.