I solved it with an helper and some trick.
Every day, I run from crontab a script that produces a config file (included
in cake) fetching the possible banners from the DB and creating a php file
with the banner definitions...
Something like:
define('BANNER1', serialize(array('3.jpeg' => 'http://www.example.com', '
125x600.jpg' => '/banners')));
define('BANNER2', serialize(array('4.jpg' => 'http://www.example2.com', '
125x600.jpg' => '/banners')));
( in my case the array contains the banner image and its destination and the
default image + destination in case the banner doesn't have to be
displayed).
Then in my helper I just random pick the constant to show.
Might not be the best solution if you have highly dynamic banners, but in
that case you could lower the intervals on your crontab and you would have
just a small delay between the time the banner is uploaded and the time it
starts showing.
Works fine for me.
Hope it helps.
On 6/14/07, Katarzyna Gogolek <[EMAIL PROTECTED]> wrote:
>
> hi
>
> I want to write a snippet that would select a random banner from the
> database and display it on screen. banners belong to different size
> categories, and I would like the person who will be using this website to
> decide where the banners would appear easily. Therefore i would like them to
> be able to insert a code like:
>
> <?php $randombanner('size') ?> in any part of a view file that they
> select, and then the script to randomly choose a banner of the defined size.
>
> and here's where the problem is.
> I don't quite understand what how should I define the script, as:
>
> a) if I choose it to be component - I can't execute it from the view level
> b) if I choose it to be helper and gather all banners from the database in
> e.g. app_controller, then it's not very efficient as with every load of
> any page, it will run a search through the mysql database, even if there's
> no need for the banner on that page. as well es I would have to execute the
> code this way <?php $randombanner('size',$banners) ?> where $banners is an
> array of all my banners available.
>
> sorry if the question is daft, but I'm new to cakePHP and still have some
> problems with understanding how it works.
>
> many thanks
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---