Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to pass variables from CakePHP to JavaScript

    • 0
    • 2
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.42k
    Comment on it

    Hello All,


    In this blog we will discuss about how to pass CakePhp variable in javascript.

    So firstly we will be initiallizing a variable in the function below i.e abc(),then set this variable in for the ctp file.

    Example-

    function abc(){
    
    $this->layout=default;
    $message="Hello;
    $this->set('message'.$message); 
     }
    

    Then in your abc.ctp you can access the variable by following conventions:-

    Example-

    <script type="text/javascript">
    var message = <?php echo $message; ?>;//You can get the value set in from your controller
    var wishing = Hello+message;
    alert(wishing);
    </script>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: