Zand Php Cake Php

Posted by : park
"approved" field for a model
Hi,

Would like to add an "approved" field for a model. Users can only see
entries whose Model.approved = 1. Only in admin section can unapproved
entries be retrieved.

It's an existing site, so I don't want to rewrite conditions for all
find queries.

Is there a centralized method (presumably in Model) of achieving this?

Many thanks!
 
 
Posted by : JamesF
Re : "approved" field for a model
ahh thats why we should be using fat models instead of fat

controllers.



the most direct way to achieve this would be to put it in each find

call.



the best way would be to set up a function in your model, lets call it

findApproved()



so in you model you put



function findApproved(){



    $data = $this->find('all', array('conditions'=>array

('Model.approved'=>1,

more conditions etc etc)));



     return $data;



}



in your controller just put

$this->Model->findApproved() in place of those old rusty controller

find calls.
 
 
If you have the better reply, then send it to us. We will display your reply after the approval.
Name : 
Email Id :   
Reply :