21294 Posts in 5734 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1562 Views |
-
Routing to an action

19 November 2009 at 10:37am
Is there are way to use Director::addRules() to route to a particular action on a controller? For example, I want to do something like
Director::addRules(10, array(
'confirm//$ID' => array('Controller'=>'AccountPage_Controller', 'Action' => 'confirm')
));So if someone visits /confirm/23 it'll go to AccountPage_Controller::confirm() (and pass ID = 23 in $request).
-
Re: Routing to an action

19 November 2009 at 3:26pm
You don't need to specify an action as anything coming in to the rule will go to the controller::index function.
Director::addRules(10, array(
'confirm//$ID' => 'AccountPage_Controller'
));This will route anything from /confirm* to the AccountPage_Controller. From there you can process either by action (/confirm/me to AccountPage_Controller function me()) or by handling it in the index() function.
All values passed on the URL will be available in the array $this->urlParams. So with the above rule in place in your AccountPage_Controller:
public function index() {
if( isset($this->urlParams['ID']) and is_numeric($this->urlParams['ID'])) ) {
// call some confirmation code with $this->urlParams['ID'])
}
| 1562 Views | ||
|
Page:
1
|
Go to Top |


