Jump to content
Larry Ullman's Book Forums

Controller Parameters


snapper
 Share

Recommended Posts

When I create this method actionTest($parameter){

                                                            print($parameter);

                                                            }

inside of a controller and attempt to access it in the browser I get an error 400.

 

How can I set up yii so that if I enter:

/controller/test/text  it would simply print the string 'text' on the screen instead of returning an invalid request error?

 

I already verified that the URL is correct. If I write actionTest(){  print('text'); } and then go to /controller/test/text then it works just fine. 

 

How can I set up yii so that a controller action can accept parameter values in the URL?
Link to comment
Share on other sites

You need to configure your routes in the configuration file to indicate that this particular action takes a parameter. The chapter on controllers explains how to do this. I don't know off the top of my head if you could make it so that any controller action works with that format, but you wouldn't want to be that generic about it anyway.

Link to comment
Share on other sites

Thanks, that answered my question. Just out of curiosity, why wouldn't I want to be that generic with my parameter names. With some other frameworks, I could just write a function with parameters without any change to a config file and they work. Why would you recommend not having that feature here?

Link to comment
Share on other sites

 Share

×
×
  • Create New...