database - CakePHP, number of views -
suppose, db table in project :
<table> <tr> <th>id</th> <th>title</th> <th>description</th> <th>created</th> <th>modified</th> <th>........</th> </tr> <tr> <td>1</td> <td>some title</td> <td>some description</td> <td>7/8/2013 8:50</td> <td>7/8/2013 8:50</td> <td>........</td> </tr> </table> now, want number how many times record 1 (id=1) has been seen. , in cakephp. there easy way information ? know created , modified 2 fields values automatically generated cakephp. so, there field or can used here ? marked ......... . or, there other way ? thanks.
there's nothing built-in, it's not hard make yourself. (the hard part not increment counter when search engine bots access page if it's reachable them.)
in database create field viewcount int default 0 example. in controller, assuming model called model , action view (replace actual names), add code increments counter when page viewed:
function view( $id ) { // .... $this->model->updateall( array( 'model.viewcount', 'model.viewcount + 1' ), array( 'model.id', $id ) ); }
Comments
Post a Comment