8000 [TO TEST] URL parameters are not taken in to consideration if using default controller/method · Issue #213 · panique/mini · GitHub
[go: up one dir, main page]

Skip to content

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

Open

Description

@bestdamnfriend

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

        }

    }

}

Activity

  1. 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
  2. panique commented on Jul 31, 2016

    @panique
    Owner

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

  3. panique commented on Aug 1, 2016

    @panique
    Owner

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

  4. bdiazc90 commented on Sep 25, 2016

    @bdiazc90

    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!

  5. panique commented on Sep 25, 2016

    @panique
    Owner

    @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 ?

  6. bdiazc90 commented on Sep 26, 2016

    @bdiazc90

    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!

  7. panique commented on Sep 26, 2016

    @panique
    Owner

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0