Frank Vèssia Posted September 25, 2011 Share Posted September 25, 2011 I'm trying to count the total page i have in one category but i get this error: FATAL ERROR: ALLOWED MEMORY SIZE OF 67108864 BYTES EXHAUSTED (TRIED TO ALLOCATE 80 BYTES) IN /HOME/LIBROLO/PUBLIC_HTML/WIRE/CORE/PAGES.PHP ON LINE 290 this is my code $total=$pages->get(1485)->find("template=libro"); echo $total->getTotal(); my total is almost 7000 pages. Till 4500 was fine, no error. Link to comment Share on other sites More sharing options...
Pete Posted September 25, 2011 Share Posted September 25, 2011 I think pages->get would be getting everything - fields, images etc, so that will take some memory. I wonder if there's a pages->count instead? Link to comment Share on other sites More sharing options...
Frank Vèssia Posted September 26, 2011 Author Share Posted September 26, 2011 for using $page->count i need first make a query with get o find method... Link to comment Share on other sites More sharing options...
Pete Posted September 26, 2011 Share Posted September 26, 2011 In which case I'd use a normal database query - couldn't see any docs on the site after the briefest of searches, but this thread should help you out: http://processwire.com/talk/index.php/topic,23.0.html Since $db is all set up and ready to go it's likely more efficient to do it this way. Oh, but for total pages in a category that won't work will it? Erm... not sure how you'd do that - you'd need some sort of function to find all child categories and then use a query based on those IDs to count the child pages. Sorry, not being too much help here Link to comment Share on other sites More sharing options...
ryan Posted September 26, 2011 Share Posted September 26, 2011 That's way too many pages to try and load in memory at once. I'm impressed you were able to load that many. When you start dealing with hundreds or thousands of pages, start using "limit=n" to paginate whether for output or not. How many pages you can load at once depends on how many fields are being auto-joined to it and how much memory you have available to PHP. Here's are two ways to achieve what you want below. This one loads a max of 3 pages. In the first example, we specify "limit=2" because any limit above 1 triggers PW's pagination (making it include the total matches). So we take advantage of that to get the total: $total = $pages->get(1485)->find("template=libro, limit=2")->getTotal(); This next example requires PW 2.1. We use a "has_parent=1485" in the selector, which is a way to tell PW that the matched pages have to have that parent somewhere in their ancestors . That's something that the first example is doing for you since you are already specifying the parent by calling the find() directly from page 1485. $total = $pages->count("has_parent=1485, template=libro"); Link to comment Share on other sites More sharing options...
Frank Vèssia Posted September 26, 2011 Author Share Posted September 26, 2011 thanks Ryan, the second example works good. 8) I cannot use limit because i need to know the total of pages in my archive. P.S: now I count 14k pages. Link to comment Share on other sites More sharing options...
ryan Posted September 26, 2011 Share Posted September 26, 2011 You can use limit. As long as specify a limit greater than 1, PW will still count the pages even if it doesn't load them. When you call getTotal() it tells you the total number of matches as if there were no limit. It has to do this for pagination, but it's a trick that's handy to know about even when you don't need pagination. Link to comment Share on other sites More sharing options...
Frank Vèssia Posted September 26, 2011 Author Share Posted September 26, 2011 ohhh fine, good trick Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now