In App.php file I have this:
For URL like this one: http://mywebroot/myapp/param1/param2
# anything leftover in $url, set as params, else empty.
$this->params = $url ? array_values($url) : [];
print_r($this->params); // this gives me dumped array values as it should
// so I can see Array ( [0] => param1 [1] => param2 )
// Now I am trying to pass that array to my controller:
//
//
# call our method from requested controller, passing params if any to method
call_user_func_array([
$this->controller,
$this->method
], $this->params); // Don't worry about `$this->controller`,
// `$this->method` part, it will end up calling method from the class bellow.
In my controller file I have:
class Home extends Controller {
// here I am expecting to catch those params
//
public function index($params = []){
var_dump($params); // This gives `string 'param1' (length=6)`? WHERE IS ARRAY?
// not relevant for this question
# request view, providing directory path, and sending along some vars
$this->view('home/index', ['name' => $user->name]);
}
So my question is, why in my controller I dont have that $params as array, but just first element of array.
If I instead do:
public function index($param1, $param2){
I will have all of them, but I want flexibility in terms of how many of params I will get.