Last Updated: September 09, 2019
·
2.864K
· narven

Call current controller / method in CodeIgniter dynamically

// call current class
$this->router->class;

// call current method
$this->router->method;

USAGE

When loading a view from the controller instead of hardcoding your views names. you can do something like

$this->load->view("{$this->router->class}/{$this->router->method}");

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside