Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a helper function in a controller?

I wrote some function in app_helper file. now i need to call that function in my controller how i can do this in CAKEPHP

like image 789
AnNaMaLaI Avatar asked Jun 23 '11 07:06

AnNaMaLaI


People also ask

Can we use helper method in controller Rails?

In Rails 5, by using the new instance level helpers method in the controller, we can access helper methods in controllers.

Can we call controller method in Helper?

You generally don't call controller-methods from helpers. That is: if you mean a method that collects data and then renders a view (any other method that needs to be called should probably not be in a controller). It is definitely bad practice and breaks MVC.


1 Answers

You can use Component, they are stored in Controller/Component/

For example if you have Controller/Component/SomeComponent.php and want call it on the fly in single action inside controller:

$this->SomeComponent = $this->Components->load('SomeComponent');
$this->SomeComponent->someFunction();
like image 172
Sojtin Avatar answered Oct 07 '22 01:10

Sojtin