On Wed, Mar 4, 2009 at 10:58 AM, aman batra <[email protected]> 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/latest for latest data
> www.abcd.com/popular for popular and so on
>
> now i want something like
> www.abcd.com/latest/vid gives me all latest videos
> www.abcd.com/popular/doc gives 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 [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
-~----------~----~----~----~------~----~------~--~---