0

I'm trying to call a controller and method pulled from the URI site.com/controller/method

Here is my current working code:

    $__REQUEST__ = new URI_Request($_SERVER["REQUEST_URI"]);

    $this->prepareController($__REQUEST__);

    if($this->checkClass()) {
        $this->controller = new $this->controller();

        if($this->checkMethod($__REQUEST__)) {
            $method = $__REQUEST__->getMethod();
            $this->method = $method;
            $this->controller->$method();
        }
    }

However, I want this line

$this->controller->$method(); 

To work as similarly to this

$this->controller = new $this->controller();
//achieves something like $this->controller = new IndexController();
//if the URL was something like site.com/index/test (/index/ gets manipulated)

i.e. something like

$this->controller->$this->method

I can see why this wouldn't work, however - is there a way to chain this or get it to reference the $method variable from the object characteristics rather than a stray variable?

1 Answer 1

1
$this->controller->{$this->method}();
Sign up to request clarification or add additional context in comments.

2 Comments

Could you give a little context as to how it works? I'm not sure where I'd read up on this
@Jackhardcastle Dntknw )) curly brackets this is "markers". I think, it begin from this: php.net/manual/en/language.variables.variable.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.