1. MODEL

$this->Test->scraper($shop, $author)

The function scraper() gets $shop(the name of a internet bookshop site)
and $author as arguments and returns a title list of the first 10 books
being sold there with $author as the author.

$booklist = $scraper('amazon','Shakespeare');
will return.

$booklist[1] = 'Romeo and Juliet'
$booklist[2] = 'One Summer Night's Dream'
...
$booklist[10] = 'Tempest'

2. CONTROLLER

let's suppose that I have a list of 50 bookshops.

$shoplist[1] = 'amazon'
$shoplist[2] = 'barnsandnoble'
...
$shoplist[50] = 'borders'

I want to fetch the titles of 10 books from each shop and output them
so that the user can see the list from the 50 shops without needing to
visit each of the 50 shops. OK? So I'm thinking about meta search
engine. The expected output is like this:

*10 books from amazon
Romeo and Juliet
One Summer Night's Dream
...
Tempest
*10 books from barnsandnoble
King Lear
Hamlet
...
Romeo and Juliet

and so on.

At first my code was like the following:

$totalbooklist = array();
for ($i == 1; $i <= 50; $i++) {
 $booklist = $this->Test->scraper($shoplist[$i],'Shakespeare');
 $totalbooklist = am($result, $booklist);
}
$this->set('totalbooklist', $totalbooklist);

3. VIEW

<?php
//No headers like "* 10 books from amazon" yet.
$count = count($totalbooklist);
for ($i == 1; $i <= 50; $i++)
echo totalbooklist[$i];
?>

It works either way. But the problem is that it makes the user wait too
long. Let's suppose that fetching 10 books from a bookshop takes 2
seconds, then it means that the user has to wait 100 seconds for all 50
shops, staring an empty computer screen! Too unkind to the users!
So I changed my mind not to "append" booklists into a totalbooklist
since it is too time-consuming, and instead want to  output "on the
fly". By "on the fly" I mean each list of 10 books from a bookshop is
outputed seperately instead of being appended into a total book list. I
could say "appending" is done not in Controller, but in View.
What is important is "Do not make the user wait!."

Without CakePHP or any other MVC frameworks, I would have coded like
the following to accomplish "on the fly" output.

for ($i == 1; $i <= 50; $i++) {
   echo "* 10 Books from" . $shoplist($i) . "\n";//This is a Header.
   $booklist = $this->Test->scraper($shoplist[$i],'Shakespeare');
   for ($j == 1; $j <= 10; $j++) {
     echo $booklist[$j];
   }
}

But I'm using Cake which require communication between Controller and
View, and came across the "wait time is too long" problem I mentioned
above. Maybe the structure of my application needs to change. Could
anyone help me? Any comments would be much appreciated. Thanks for
readng my long thread.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to