Sounds like you need to have a line of code in the controller's view method
that calls a simple model function:
$this->Model->increment($id);
In the model:
function increment($id) {
$this->updateAll(array('Model.view_count' => 'Model.view_count+1'),
array('Model.id' => $id));
}
Or you could just call it directly from the view method in the controller:
$this->Model->updateAll(array('Model.view_count' => 'Model.view_count+1'),
array('Model.id' => $id));
This way, whenever the view method is called (in other words, each time the
page is rendered) you increment the view_count field by one.
Jeremy Burns
Class Outfit
[email protected]
http://www.classoutfit.com
On 11 Feb 2011, at 03:31, [email protected] wrote:
> Hi Jeremy,
> What I'm looking for is to set the data,... say to set field views in
> Video table increment by 1 every time page accessed. To set data,...
> NOT to retrive.
>
> Thanks
> chris
>
>
>
> On Feb 10, 1:11 pm, Jeremy Burns | Class Outfit
> <[email protected]> wrote:
>> RTFM.http://book.cakephp.org/
>>
>> Jeremy Burns
>> Class Outfit
>>
>> [email protected]http://www.classoutfit.com
>>
>> On 10 Feb 2011, at 20:57, [email protected] wrote:
>>
>>
>>
>>
>>
>>
>>
>>> Hi Mike,
>>> Yes, I know that I have to read from table,...
>>> But I don't know how... LOL
>>> the code... anyone can help...?
>>
>>> Thanks
>>> chris
>>
>>> On Feb 10, 11:59 am, mike karthauser <[email protected]> wrote:
>>>> On 10 Feb 2011, at 17:30, "[email protected]" <[email protected]> wrote:
>>
>>>>> Hi All,
>>>>> How u All Doinnn...?!
>>
>>>>> Can anyone teach me how to setup views,... so when page is
>>>>> accessed ... it will set field views="increment numbers" like Video
>>>>> views=906, Group views=489, etc.. like how many time page has been
>>>>> accessed.
>>
>>>> You won't be doing any counts in the view, rather updating the count when
>>>> the action is called and passing that value to the view.
>>
>>>> All you'll need to do is to get a count value from your table and then
>>>> resave it after you have added 1. You may also want to do this as an ajax
>>>> call in JavaScript when you have played say half of the video as then it
>>>> won't be affected if bots hit the page or people refresh loads
>>
>>>>> Thanks
>>>>> chris
>>
>>>>> --
>>>>> Our newest site for the community: CakePHP Video
>>>>> Tutorialshttp://tv.cakephp.org
>>>>> Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp
>>>>> others with their CakePHP related questions.
>>
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected] For more options, visit this group
>>>>> athttp://groups.google.com/group/cake-php
>>
>>> --
>>> Our newest site for the community: CakePHP Video
>>> Tutorialshttp://tv.cakephp.org
>>> Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
>>> others with their CakePHP related questions.
>>
>>> To unsubscribe from this group, send email to
>>> [email protected] For more options, visit this group
>>> athttp://groups.google.com/group/cake-php
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at
> http://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php