How to call codeigniter controller function from view? When i call the function in a controller, get a 404 page.
You can call the helper function in Codeigniter using the function name in the view file. To call a helper method you have to first create a helper method in the helper file, autoload it in the base controller or controller's method after that you can access it in your controller and view files.
You can call controller function from view in the following way:
Controller:
public function read() { $object['controller'] = $this; $this->load->view('read', $object); }
View:
// to call controller function from view, do $controller->myOtherFunct();
Codeigniter is an MVC (Model - View - Controller) framework. It's really not a good idea to call a function from the view. The view should be used just for presentation, and all your logic should be happening before you get to the view in the controllers and models.
A good start for clarifying the best practice is to follow this tutorial:
https://codeigniter.com/user_guide/tutorial/index.html
It's simple, but it really lays out an excellent how-to.
I hope this helps!
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