Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Set more than one variable in CakePHP

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 128
    Comment on it

    set() method provides a way to set values in our cake-php controller so that we can use it in our view for presentation.

    Syntax of set is: $this->set('variable','value')

    In cakephp controller, we can set the values as

    <?php 
    $this->set('var1','value1'); 
    $this->set('var2','value2'); 
    $this->set('var3','value3'); ?>
    

    In above code , we are using 3 set method to set variables to use it in view but we can do the same in a single set method using compact() method.

    Example: To set more than one variable/value in our controller

    $var1 = value1; $var2 = value2; $var = value3;
    $this->set(compact('var1','var2','var3'));
    

 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: