You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[TO TEST] URL parameters are not taken in to consideration if using default controller/method #213
Analysing application.php, I see a lot of nested if statements, which causes the URL parameters to only be passed to call_user_func_array() if the selected controller and method are found, and not if the defaults are used. For example:
localhost/mini/home/index/4 sends the parameter 4 localhost/mini/home/4 throws an error localhost/mini/4 throws an error
You'd be better off checking each part of the URL individually, reverting to defaults if need be. Then, call_user_func_array will always run. This is my rewritten application.php:
class Application {
private $url_controller = 'home';
private $url_action = 'index';
private $url_params = array();
public function __construct() {
$url = $this->parseUrl();
if (file_exists('../application/controller/' . $url[0] . '.php')) {
$this->url_controller = $url[0];
unset($url[0]);
}
require_once '../application/controller/' . $this->url_controller . '.php';
$this->url_controller = new $this->url_controller;
if (isset($url[1])) {
if (method_exists($this->url_controller, $url[1])) {
$this->url_action = $url[1];
unset($url[1]);
}
}
$this->url_params = $url ? array_values($url) : array();
call_user_func_array([$this->url_controller, $this->url_action], $this->url_params);
}
public function parseUrl() {
if (isset($_GET['url'])) {
return $url = explode('/', filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL));
}
}
}
changed the title [-]URL parameters are not taken in to consideration if using default controller/method[/-][+][TO TEST] URL parameters are not taken in to consideration if using default controller/method[/+]on Jul 31, 2016
@bdiazc90 hi, thanks back! :) does a home controller and an about method exist ? if so, then your apache/nginx settings might be broken, or the installation itself has a problem. I can only recommend to use the autoinstaller and then try to reproduce the error, if you cannot reproduce then it might be your settings... Can you post more details on your problem ?
Hi @panique! Thanks for your answer, I had been looking for solving my problem in the code.
I did it! I just copy all the MINI package to my localhost and update with my project.
This is a great (semi) framework, I love it!
Activity
[-]URL parameters are not taken in to consideration if using default controller/method[/-][+][TO TEST] URL parameters are not taken in to consideration if using default controller/method[/+]panique commentedon Jul 31, 2016
Thanks for the commit, I'll test this soon!
panique commentedon Aug 1, 2016
btw the normal way to do this: simply dont use the default method for actions with parameters :)
bdiazc90 commentedon Sep 25, 2016
Hello @panique thanks for your amazing contribution!!
I have one question about the URL:
Is it a way to use the first way and invoke the home controller with the about action??
Thanks in advance!
panique commentedon Sep 25, 2016
@bdiazc90 hi, thanks back! :) does a home controller and an about method exist ? if so, then your apache/nginx settings might be broken, or the installation itself has a problem. I can only recommend to use the autoinstaller and then try to reproduce the error, if you cannot reproduce then it might be your settings... Can you post more details on your problem ?
bdiazc90 commentedon Sep 26, 2016
Hi @panique! Thanks for your answer, I had been looking for solving my problem in the code.
I did it! I just copy all the MINI package to my localhost and update with my project.
This is a great (semi) framework, I love it!
panique commentedon Sep 26, 2016
Very cool! :) Glad it fixed your problem