Jump to content
Larry Ullman's Book Forums

Handling Parameters And Throwing Exceptions?


KeepLearning
 Share

Recommended Posts

Version 0.5

Page 150

 

Larry,

Can you please break this paragraph down or explain it another way? I've read it and re-read it numerous times. I understand the preceding and following pages, but not this paragraph and example.

 

Thanks.

 

 

"However, when you’ve identified a parameter in a rule that’s not part of the route,

it will only be passed to an action if that action’s parameter is named the same. The

earlier example code works, but this action definition with that same rule will throw

an exception (Figure 7.1):

# protected/controllers/PageController.php

public function actionView($x) {

// Etc."
Link to comment
Share on other sites

If you have a parameter in a routing rule, the action method's parameter has to use the same name. For example, the rule before this code, I believe, uses "id" as the parameter (for the page ID). So the actionView() method has to use $id for its parameter:

 

 

 

public function actionView($id) {
 

 

 

Using $x in the method definition, when the routing rule uses "id", throws an exception.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...