Skip to content
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

[TO TEST] URL parameters are not taken in to consideration if using default controller/method #213

Open
bestdamnfriend opened this issue May 27, 2016 · 6 comments

Comments

@bestdamnfriend
Copy link

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));

        }

    }

}
@panique panique 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 Jul 31, 2016
@panique
Copy link
Owner

panique commented Jul 31, 2016

Thanks for the commit, I'll test this soon!

@panique
Copy link
Owner

panique commented Aug 1, 2016

btw the normal way to do this: simply dont use the default method for actions with parameters :)

@bdiazc90
Copy link

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
Copy link
Owner

panique commented 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
Copy link

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
Copy link
Owner

panique commented Sep 26, 2016

Very cool! :) Glad it fixed your problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants