Jump to content
Larry Ullman's Book Forums

Handling Parameters And Throwing Exceptions?

Recommended Posts

Version 0.5

Page 150



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.





"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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...