Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is the best way to create global variables in CakePHP?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 259
    Comment on it

    Hello All,


    In this blog we will discuss creation of global variables in CakePhp.


    Sometimes there is a need to access a variable everytime in the application, so instead of declaring it again and again we can declare the variable globally so that it can be used anywhere in the application.

    So there comes the concept of the variables so called global variables.

    Global variables are the variables that can be accessible anywhere in the application.

    In CakePhp we can declare global variable in your app/config/core.php


    Example-

    Configure::write('variable Name','Variable Value');//How to declare the global variable in core.php
    Configure::write('BASE_URL','https://'.$_SERVER['HTTP_HOST']);//Example showing how to use the variable
    

    So as in the above example you can excess the BASE_URL variable anywhere in your cakephp application.

 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: