snapper Posted March 28, 2013 Share Posted March 28, 2013 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 More sharing options...
Antonio Conte Posted March 29, 2013 Share Posted March 29, 2013 You need to add that parameter to your route file too. Link to comment Share on other sites More sharing options...
snapper Posted March 29, 2013 Author Share Posted March 29, 2013 How do I do that? Is there any way to make it so that any controller action with a parameter will work with this URL format: controller/action/parameter Link to comment Share on other sites More sharing options...
Larry Posted March 29, 2013 Share Posted March 29, 2013 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 More sharing options...
snapper Posted March 31, 2013 Author Share Posted March 31, 2013 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 More sharing options...
Larry Posted April 1, 2013 Share Posted April 1, 2013 Making things globally simple also means making things perform poorly and allow for sloppy programming. Your routes should be cleanly defined and clearly tied to proper actions. Link to comment Share on other sites More sharing options...
snapper Posted April 2, 2013 Author Share Posted April 2, 2013 Thanks, I understand now. Link to comment Share on other sites More sharing options...
Recommended Posts