Giter Site home page Giter Site logo

Using multiple parameters about mini3 HOT 6 OPEN

panique avatar panique commented on May 22, 2024
Using multiple parameters

from mini3.

Comments (6)

hozzaq avatar hozzaq commented on May 22, 2024 1

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

from mini3.

lotfio avatar lotfio commented on May 22, 2024

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 call_user_func_array with call_user_func will solve the problem ?? have you tried that ? how would that be possible when we have to call an object method by parameters so we need the object the method and parameters like this call_user_func_array(array($this->url_controller, $this->url_action), $this->url_params); while call_user_func can only call a function with parameters (outside an object)

from mini3.

jmjuju avatar jmjuju commented on May 22, 2024

For me, when I changed it to call_user_func , it worked.
In my specific situation, my controller is "Dashboard" and my method "org". If I call example.com/dashboard/org/param1/param2/ , and If I uncomment the debug lines in the splitUrl function, it returns:
Controller: dashboard Action: org Parameters: Array ( [0] => param1 [1] => param2 )

Therefore, url_params is confirmed as an array as above. It's then passed to the controller and method/action as per line 44 in Application.
However, if my method is simply:

public function org($params){ echo gettype($params); }

it returns string.
If I change line 44 to call_user_func but change nothing else (Ie: the arguments stay exactly the same), the above function returns an array.

HOWEVER, If I change line 44 to:

call_user_func_array(array($this->url_controller, $this->url_action), array($this->url_params));

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 private $url_params = array();

So - PHP bug perhaps? Again, my skill is intermediate at best, so there might be something expected/normal that im missing here.

from mini3.

jgodstime avatar jgodstime commented on May 22, 2024

@hozzaq, Please where do i add this code?

from mini3.

hozzaq avatar hozzaq commented on May 22, 2024

@jgodstime hozzaq@9fb3578

from mini3.

mhco avatar mhco commented on May 22, 2024

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:

public function index($param1 = null, $param2 = null, $param3 = null)

OR! Or you can leave the declarations out, and use func_get_args like so:

public function index()
{
    $params = func_get_args();
    print_r($params);
}

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:

elseif (is_numeric($this->url_action)) {
    $this->url_params = array_merge([$this->url_action], $this->url_params);
    $this->url_controller->index($this->url_params);
}

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.

from mini3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.