Showing posts with label routing. Show all posts
Showing posts with label routing. Show all posts

Sunday, June 5, 2011

COLLECTION & MEMBER METHODS WITHIN A ROUTE

RubyHunt: What’s the use of the :collection and :member methods within a route? What’s the difference between the two?
melvinram: Collection adds routes to the entire collection
RubyHunt: So the collection is used to add another action inside the controller
melvinram: If you had a resource of Contacts, a collection route you might add would be delete_all_older_than_6_months
melvinram: and the route to get to it would be be/contacts/delete_all_older_than_6_months/
RubyHunt: Which otherwise would be restricted to only 7 actions ?
melvinram: yes
melvinram: A member method applies only to one record. For example, you might add a member method called upgrade_to_vip that would update one record to have a status of VIP or something…
melvinram: And the route would be /contacts/1/upgrade_to_vip
RubyHunt: So the :collection is used to add action inside a RESTful controller and the :member would be used to apply action for individual object.
melvinram: you got it!

Tuesday, March 2, 2010

Cakephp的奇怪

我唔知到係咪ror都係咁。。。但而家既做法變左係咁。。。
Router::connect('/:language/:controller/:action/',
array(),
array('language' => '[a-z]{2}'));
呢句係囉黎接所有既action format要好似上面所寫咁

Router::connect('/:language/:controller/:action/:id',
null,
array('pass' => array('id'),'language' => '[a-z]{2}','id' => '[0-9]+'));
呢句係囉黎接所有既action format要好似上面所寫咁,但佢會support id既。。。但記住id係要pass既。。。。唔pass佢唔知點解食唔到。。。。=-=

Router::connect('/:language/:controller/:action/*',
null,
array('language' => '[a-z]{2}'));

如果唔記得加呢句。。。。你唔洗指意放工。。。。佢係對應呢句
link(__('Book now', true), array('controller'=>'hotel_enquiries','action' => 'submitinfo','language' => $WEB_LANG,$package['Hotelpackage']['id']));?>
因為呢句pass左個好hotelpackage.id比佢。。。

佢如果要係一個$html->link到加一個language,就要用佢
echo $html->link(__('Login',true),array('controller'=>'users', 'action'=>'login','language' => $WEB_LANG));
有時你只係想改佢既language而唔係改佢contoller同action就用佢

echo $html->link(__('English',true),array('language' => HK,"id"=>$id));
但要留意。。。有時你係要有id。。。無左佢。。。你又會進入另一個ot既世界。。。。so
記住。。。