Skip to content

Instantly share code, notes, and snippets.

@janetriley
Last active August 29, 2015 14:08
Show Gist options
  • Save janetriley/28e3656d2d54d78d3aab to your computer and use it in GitHub Desktop.
Save janetriley/28e3656d2d54d78d3aab to your computer and use it in GitHub Desktop.

Revisions

  1. janetriley revised this gist Nov 8, 2014. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion index.php
    Original file line number Diff line number Diff line change
    @@ -62,4 +62,15 @@ function mergeArray($a,$b)


    //Overwrite the base values with whatever overrides were set
    $config = mergeArray( $base_config, $local_overrides);
    $config = mergeArray( $base_config, $local_overrides);


    // if not already specified in local-main,
    // specify how many levels of call stack should be shown in each log message
    defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);


    //Start the application as usual
    require_once($yii_path);
    include('global.php');
    Yii::createWebApplication($config)->run();
  2. janetriley revised this gist Nov 8, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions protected_config_local-main-template.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    <?php
    //local-main-template.php can be checked into version cotrol
    //Copy this to local-main.php
    //protected/config/local-main-template.php can be checked into version cotrol
    //Copy this to protected/config/local-main.php
    //Ensure that .gitignore includes local-main.php your settings aren't pushed to other environments.


  3. janetriley revised this gist Nov 8, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion index.php
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,8 @@
    $local_overrides = include($local_config_path);
    }

    //This method isn't available yet in our version of Yii
    //This method isn't available yet in our version of Yii - got to wait for 1.1.16.
    //Cut and pasted from
    //https://github.com/yiisoft/yii/blob/1.1.16-branch/framework/collections/CMap.php
    /**
    * Merges two or more arrays into one recursively.
  4. janetriley revised this gist Nov 8, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion protected_config_local-main-template.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    <?php
    //local-main-template.php can be checked into version cotrol
    //Copy to local-main.php
    //Copy this to local-main.php
    //Ensure that .gitignore includes local-main.php your settings aren't pushed to other environments.


    // LOCAL Yii Path
    //Define the Yii directory path on your machine, relative to this config file
  5. janetriley revised this gist Nov 8, 2014. 2 changed files with 2 additions and 13 deletions.
    9 changes: 1 addition & 8 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -61,11 +61,4 @@ function mergeArray($a,$b)


    //Overwrite the base values with whatever overrides were set
    $config = mergeArray( $base_config, $local_overrides);



    //Start the application
    require_once($yii_path);
    include('global.php');
    Yii::createWebApplication($config)->run();
    $config = mergeArray( $base_config, $local_overrides);
    6 changes: 1 addition & 5 deletions protected_config_local-main-template.php
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,7 @@
    //local-main-template.php can be checked into version cotrol
    //Copy to local-main.php

    //These will be executed before returning local settings.
    //Set local values here if they're different from main.

    //LOCAL Yii Path
    //Is Yii installed in a different location on this machine?
    // LOCAL Yii Path
    //Define the Yii directory path on your machine, relative to this config file
    $yii_path=dirname(__FILE__).'/../../YOUR_DIR/yii.php';

  6. janetriley revised this gist Nov 8, 2014. 2 changed files with 13 additions and 2 deletions.
    9 changes: 8 additions & 1 deletion index.php
    Original file line number Diff line number Diff line change
    @@ -61,4 +61,11 @@ function mergeArray($a,$b)


    //Overwrite the base values with whatever overrides were set
    $config = mergeArray( $base_config, $local_overrides);
    $config = mergeArray( $base_config, $local_overrides);



    //Start the application
    require_once($yii_path);
    include('global.php');
    Yii::createWebApplication($config)->run();
    6 changes: 5 additions & 1 deletion protected_config_local-main-template.php
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,11 @@
    //local-main-template.php can be checked into version cotrol
    //Copy to local-main.php

    // LOCAL Yii Path
    //These will be executed before returning local settings.
    //Set local values here if they're different from main.

    //LOCAL Yii Path
    //Is Yii installed in a different location on this machine?
    //Define the Yii directory path on your machine, relative to this config file
    $yii_path=dirname(__FILE__).'/../../YOUR_DIR/yii.php';

  7. janetriley revised this gist Nov 8, 2014. 1 changed file with 35 additions and 0 deletions.
    35 changes: 35 additions & 0 deletions protected_config_local-main-template.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    <?php
    //local-main-template.php can be checked into version cotrol
    //Copy to local-main.php

    // LOCAL Yii Path
    //Define the Yii directory path on your machine, relative to this config file
    $yii_path=dirname(__FILE__).'/../../YOUR_DIR/yii.php';

    // Crank up the debug!
    defined('YII_DEBUG') or define('YII_DEBUG',true);

    // specify how many levels of call stack should be shown in each log message
    defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);


    // Redefine any of the properties in main.php here
    // They'll be merged in index.php

    return array(
    'name'=>'My Local Yii Server',
    // application components
    'components'=>array(
    'db'=>array(
    'connectionString' => 'mysql:host=YOUR_DB_HOST;dbname=YOUR_DB_NAME',
    'username' => 'YOUR_DB_LOGIN',
    'password' => 'YOUR_DB_PASSWORD',
    ),
    ),
    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    'params'=>array(
    // this is used in contact page
    'adminEmail'=>'[email protected]',
    ),
    );
  8. janetriley created this gist Nov 8, 2014.
    64 changes: 64 additions & 0 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    <?php
    //An excerpt from Yii's index.php file

    $yii_path=dirname(__FILE__).'/yii/yii.php';

    //The default set of config settings
    $base_config = require(dirname(__FILE__).'/protected/config/main.php');


    // Optionally redefine local settings in $local_config_path. These include:
    // * your $yii_path path, relative to index.php
    // * define YII_DEBUG,
    // * your local database settings
    //
    // $local_config_path will execute any code as well, so you can define trace level

    $local_overrides = array();

    //An optional
    $local_config_path = dirname(__FILE__).'/protected/config/local-main.php';

    if( file_exists($local_config_path)){
    $local_overrides = include($local_config_path);
    }

    //This method isn't available yet in our version of Yii
    //https://github.com/yiisoft/yii/blob/1.1.16-branch/framework/collections/CMap.php
    /**
    * Merges two or more arrays into one recursively.
    * If each array has an element with the same string key value, the latter
    * will overwrite the former (different from array_merge_recursive).
    * Recursive merging will be conducted if both arrays have an element of array
    * type and are having the same key.
    * For integer-keyed elements, the elements from the latter array will
    * be appended to the former array.
    * @param array $a array to be merged to
    * @param array $b array to be merged from. You can specify additional
    * arrays via third argument, fourth argument etc.
    * @return array the merged array (the original arrays are not changed.)
    * @see mergeWith
    */
    function mergeArray($a,$b)
    {
    $args=func_get_args();
    $res=array_shift($args);
    while(!empty($args))
    {
    $next=array_shift($args);
    foreach($next as $k => $v)
    {
    if(is_integer($k))
    isset($res[$k]) ? $res[]=$v : $res[$k]=$v;
    elseif(is_array($v) && isset($res[$k]) && is_array($res[$k]))
    $res[$k]= mergeArray($res[$k],$v);
    else
    $res[$k]=$v;
    }
    }
    return $res;
    }


    //Overwrite the base values with whatever overrides were set
    $config = mergeArray( $base_config, $local_overrides);