PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 20, 2022

[FIXED] How to call javascript function in cakePHP controller?

 January 20, 2022     cakephp, cakephp-3.0, cakephp-3.3     No comments   

Issue

How to call javascript function in controller as below

In example.js

function hello(){
  alert("hi");
}

In exampleController.php

function index(){
   hello();
}

Solution

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.



Answered By - Binary Brackets
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing