-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using multiple parameters #26
Comments
No you are wrong sir it is working perfectly just pass the url parameters to your controller method and then you can use them . you said that replacing |
For me, when I changed it to Therefore,
it returns string. HOWEVER, If I change line 44 to:
This also works. It's like I have to declare url_params as an array type again for it to work. Somehow call_user_func_array almost converts url_params into a string because it's not explicitly stated as an array in the argument line (even though it's set as an array as per So - PHP bug perhaps? Again, my skill is intermediate at best, so there might be something expected/normal that im missing here. |
this is what i do for multiple parameter call_user_func_array(array($this->url_controller, $this->url_action), array($this->url_params)); // url_action no longer get parameter for easier multiple parameter
// now you can do like //site/controller/action/param1/value1/param2/value2 and so on
if (count($url) > 2 && count($url) % 2 == 0) {
unset($url[0], $url[1]);
$param = array_values($url);
for ($i=0; $i < count($param); $i++) {
if ($i % 2 == 0) {
$params[$param[$i]] = $param[$i+1];
}
}
$this->url_params = $params;
} |
@hozzaq, Please where do i add this code? |
So this is actually already done in the base code, it's just a bit wonky and undocumented. When you go to http://example.com/controller/method/param1/param2/param3 you should hit the /controller/method/ page, with param1-3 passes as arguments (provided controller and method exist, but I'll get into that later). In order to call the parameters, you either have to declare them in the method, like:
OR! Or you can leave the declarations out, and use
Now, if you have a page, like /songs/ that you want to be able to do http://example.com/songs/1 or http://example.com/songs/1/edit etc, you can place the following code just after line 54:
The only problem I've run into with this method is that your controller file can get a bit messy if you have a bunch of methods in that file. This isn't really an issue with the way the site works (because you'd want /songs/bldfkjashfk to return a 404 error page), but more of what happens when a project doesn't have detailed documentation like the big projects tend to have. This can easily be remedied by writing a bit of a "how-to" on this, so it's not as confusing. Also, since this is just a framework, it's not meant to be the 100% solution to every problem you'll face, just a strong base to start your work from; some assembly will be required. @panique You can probably close this issue, and open an ongoing task about creating documentation for the project to alleviate any future confusion. |
If someone has multiple parameters:
eg: http://example.com/controller/method/param1/param2/param3/
Then call_user_func_array only allows one parameter to be passed to the method ("param1") as a string.
Replacing 'call_user_func_array' with 'call_user_func' on line 44 of Application.php will enable the user to have multiple parameters sent as an array.
Given the line in the splitUrl function:
$this->url_params = array_values($url);
One can only assume that passing parameters as an array was always the intention? Or am I mistaken (My php is intermediate at best...so I might be missing something here..)
The text was updated successfully, but these errors were encountered: