function latest()
   {
                $this->paginate = array('Entity'=>array('fields'=>array
('Entity.title','Entity.description',
 
                                        
'Entity.user_id','Entity.thumb_url','Entity.entity_uid',
                                                                                
                'Entity.num_fachaks', 'Entity.number_of_views',
                                                                                
                'Entity.rating', 'Entity.entity_ext', 'Entity.service'),
                                                                                
'order' => 'Entity.created DESC',
                                                                                
'limit'=>21,
                                                                                
'recursive'=>-1));

                if (!isset($this->params['year']) || 
!isset($this->params['month'])
                                || !isset($this->params['day'])) {
                        $entities = $this->paginate('Entity', 
array('Entity.status'=>'Y',
                                        'Entity.approved'=>'Y'));
                }
                else {
                        $datestr = 
$this->params['year'].'-'.$this->params['month'].'-'.
$this->params['day'];
                        $date = date('Y-m-d', strtotime($datestr));

                        $entities = $this->paginate('Entity', 
array('Entity.created >='=>
$date,
                                        'Entity.status'=>'Y', 
'Entity.approved'=>'Y'));
                }

                $this->set('res', $entities);
   }

this is my latest function. what should be done?? and the way u r
saying is a change in every action..right?? can this be done through
beforeFIND??

On Mar 5, 4:17 am, brian <bally.z...@gmail.com> wrote:
> On Wed, Mar 4, 2009 at 10:58 AM, aman batra <batra_aman2...@yahoo.com> wrote:
>
> > hello,
> > i want to filter the data on the basis of its type i.e whether it is a
> > document, or video or ppt, how should i do that. currently my finder
> > query results the mix of the formats according to the condition
> > supplied. I have an entities_controller.php which has the actions as
> > latest, popular, browse which all result me the paginate result of
> > entities and set a common variable for the view. and my url looks like
> >www.abcd.com/latestfor latest data
> >www.abcd.com/popularfor popular and so on
>
> > now i want something like
> >www.abcd.com/latest/vidgives me all latest videos
> >www.abcd.com/popular/docgives me all the popular documents and so on
> > for rest of the actions
>
> > what should i alter in my code to make it generic so that one change
> > can do this all.. is something done in model entity.php beforeFind or
> > any other sort of approch anyone suggests. i can send the code if
> > wanted for this if problem is not understood.
>
> If you have a route like:
>
> Router::connect(
>         '/latest',
>         array(
>                 'controller' => 'entities',
>                 'action' => 'latest' // or whatever your method is
>         )
> )
> ... you can do something like:
>
> Router::connect(
>         '/latest/:type',
>         array(
>                 'controller' => 'entities',
>                 'action' => 'latest' // or whatever your method is
>         ),
>         array(
>                 'type' => '[\+\-_A-Za-z]+', // or whatever is appropriate
>                 'pass' => array('type')
>         )
> )
>
> Change your method signature to, eg:
>
> function latest($type = null)
> {
>
> If $type is not null, add it to your find conditions
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to