How to call javascript function in controller as below
In example.js
function hello(){
alert("hi");
}
In exampleController.php
function index(){
hello();
}
You can't call JavaScript function from the controller,
controller is running on server-side, and your java script code running under the browser/client side.
If you want to call javaScript function you must have to render view and call from that.
You can also try
$this->Html->scriptBlock('alert("hi")');
code to call javaScript function from the view.