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
-~----------~----~----~----~------~----~------~--~---

Reply via email to