Results 1 to 2 of 2

Thread: Where to save application static information

  1. #1
    Join Date
    May 2017

    Lightbulb Where to save application static information

    I'm writing an application in CakePHP application.

    I want to make the application fully dynamic and separate static values from website and just use a pointer to them wherever is used.

    Ex, my application name is 'profplus' and slogan is 'make profile easy'

    If I use them directly in different pages, in future in case they are required to be changed, changes are to be made to all files wherever these values exists and thus requires a lot of work to do.

    I wan to save them at a single place like
    PHP Code:
    $APP['name'] = 'profplus';
    $APP['slogan'] = 'make profile easy'
    and them use them every where like
    PHP Code:
    <?= $APP['name'?>
    I have following ways to do this.

    1. Store data in the database
    2. define somewhere and include like
      PHP Code:
    3. or use staticaly everywhere

    Which could be the best strategy to do this?

  2. #2
    Join Date
    May 2016
    Southern California
    A database may be unnecessary if this content does not change throughout the use of your app. But if you or a user wants to be able to change the content from a form, then a database is best. My choice otherwise would be to use constants.

    Create a config.php file and assign your constants there.
    PHP Code:
    // config.php
    define('APP_SLOGAN''make profile easy');

    // then in your main index.php
    require "config.php"
    As an alternative, you can use an array, like you mentioned.

    PHP Code:
    // config.php
    return array(
    'app_name' => 'profplus',
    'app_slogan' => 'make profile easy'

    // then on any page assign variable
    $config = include 'config.php'
    Difference here, depending on your setup, is you would then include config.php when/where you need it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center