Let say I am at my View loaded by my controller named Book.
Is there any way for me to get my controller’s URL at View instead of manually typing:
echo base_url('book');
The base URL of the site can be configured in application/config/config. php file. It is URL to your CodeIgniter root.
The fetch_class() and fetch_method() method of Router class can be used to read the class and method property in CodeIgniter. Use fetch_class() method to get the name of the controller or class in CodeIgniter. Use fetch_method() method to get the name of the method or function in CodeIgniter.
To return the current controller, you can use.
$this->router->fetch_class();
Equally, if you wanted to return the current method, then you could use:
$this->router->fetch_method();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With