0

Im trying to execute the following code

$our_controller = new App\Controllers\$routing->_new['controller']();

But Im getting 'Unexpected $routing'

And this is the class Im trying to load looks like

namespace App\Controllers;

class HomeController extends BaseController
{
      public function __construct()
      {
          parent::__construct();
      }
}

If I type the following

$our_controller = new App\Controllers\HomeController();

Works perfectly but I must use the variable instead of HomeController

1 Answer 1

1

Try this, I think it should work:

$namespace = 'App\Controllers\' . $routing->_new['controller']();

$our_controller = new $namespace;
Sign up to request clarification or add additional context in comments.

1 Comment

Using this piece worked with minor fixes thanks (removing the () and adding it later).

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.