Ahhhh.... that's a much cleaner solution I must say. Definately
didn't know about that one. Good stuff.
I agree with Simon though, you need to still be careful on what
happens in the beforeFilters, especially if any of them make
additional calls to the Models.
On Nov 10, 8:55 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Another, more cake based way of doing this, would be to use a
> beforeFilter, and set the (broadly undocumented at present):
>
> var $cacheAction = array('duration'=>'1 day','callbacks'=>true);
>
> in your controller. This will add calls to the before filter in your
> cached page. However, note that you'll have to be careful about any
> other work done in the beforeFilter and any Components you load, as
> all these will be initialised as well.
>
> Simonhttp://www.simonellistonball.com
>
> On Nov 9, 2:21 pm, Dave J <[EMAIL PROTECTED]> wrote:
>
> > This may not be the cleanest solution, but here goes. It's a sort of
> > 'web-bug' approach.
>
> > You could have an action in your controller (or a separate controller
> > dedicated to statistics) which will do the counting for you, and then
> > invoke it with an <img> tag in the view.
>
> > So for example, you can have
> > /articles/addviewcount/<article_id>
>
> > which would echo the contents of an empty gif image.
>
> > And then in the view, you can put something like
> > <img src="/articles/addviewcount/1234" width="1" height="1">
>
> > That way, the addviewcount action will be called, regardless if the
> > view was cached or not.
>
> > Just remember to turn off view caching for the addviewcount action.
>
> > On Nov 9, 12:05 pm, Filip Camerman <[EMAIL PROTECTED]> wrote:
>
> > > In some controller actions I do an UPDATE table SET nviews = nviews +
> > > 1 WHERE id = '{$id}' to keep track of how often the page gets viewed
> > > (for each record). Now I want to cache some of these actions, and I
> > > was wondering what would be the best way to keep counting pageviews.
> > > The first way I can think of is to put nocache tags in the view around
> > > a requestaction that would do the update query, but that would be a
> > > "dirty" way to do it. Maybe something with a before filter?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---