Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6748519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:34:30+00:00 2026-05-26T12:34:30+00:00

I have a Yii project with a main.php config file and dev.php config file

  • 0

I have a Yii project with a main.php config file and dev.php config file which “inherits” from it. The files are as follows:

main.php:

<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
    'basePath' => dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..',
    'name' => 'FeedStreem',
    // preloading 'log' component
    'preload' => array( 'log' ),
    // autoloading model and component classes
    'import' => array(
        'application.models.*',
        'application.components.*',
        'application.controllers.*',
    ),
    // application components
    'components' => array(
        'db' => array(
            'connectionString' => 'mysql:host=remote.host.com;dbname=dbnamehere',
            'emulatePrepare' => true,
            'username' => 'username',
            'password' => 'password',
            'charset' => 'utf8',
            /*'enableProfiling' => true*/
        ),
        'user' => array(
            // enable cookie-based authentication
            'allowAutoLogin' => true,
        ),
        'authManager' => array(
            'class' => 'CDbAuthManager',
            'connectionID' => 'db'
        ),
        'urlManager' => array(
            // omitted
        ),
        'errorHandler' => array(
            // use 'site/error' action to display errors
            'errorAction' => 'site/error',
        ),
        'log' => array(
            'class' => 'CLogRouter',
            'routes' => array(
                array(
                    'class' => 'CFileLogRoute',
                    'levels' => 'trace, info, error, warning',
                ),
            ),
        ),
    ),
    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    'params' => array(
        // this is used in contact page
        'adminEmail' => 'webmaster@example.com',
    ),
);

dev.php:

<?php

return CMap::mergeArray(
    require(dirname( __FILE__ ) . '/main.php'),
    array(
        'modules' => array(
            'gii' => array(
                'class' => 'system.gii.GiiModule',
                'password' => 'SECRET',
                // If removed, Gii defaults to localhost only. Edit carefully to taste.
                'ipFilters' => array( '127.0.0.1', '::1' ),
            ),
        ),
        'components' => array(
            'db' => array(
                'connectionString' => 'mysql:host=localhost;dbname=dbname2',
                'emulatePrepare' => true,
                'username' => 'username2',
                'password' => 'password2',
                'charset' => 'utf8',
            ),
            'log' => array(
                'class' => 'CLogRouter',
                'routes' => array(
                    array(
                        'class' => 'CFileLogRoute',
                        'levels' => 'trace, info, error, warning',
                    ),
                    // uncomment the following to show log messages on web pages
                    array(
                        'class' => 'CWebLogRoute',
                    ),
                ),
            ),
        ),
    )
);

However, when I use dev.php locally, I get the following error:

Warning: PDO::__construct() [pdo.--construct]: [2002] No connection could be made because the target machine actively  (trying to connect via tcp://remote.host.com:3306) in C:\web_workspace\lib\yii\framework\db\CDbConnection.php on line 405

Which tells me the dev.php did not overwrite that ‘db’ config option. How can I make a config file that inherits from main.php but can overwrite options when I merge it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:34:30+00:00Added an answer on May 26, 2026 at 12:34 pm

    As far as i see from source code it should overwrite your config:

    public static function mergeArray($a,$b)
    {
        foreach($b as $k=>$v)
        {
            if(is_integer($k))
                isset($a[$k]) ? $a[]=$v : $a[$k]=$v;
            else if(is_array($v) && isset($a[$k]) && is_array($a[$k]))
                $a[$k]=self::mergeArray($a[$k],$v);
            else
                $a[$k]=$v;
        }
        return $a;
    }
    

    Source: http://code.google.com/p/yii/source/browse/tags/1.1.8/framework/collections/CMap.php

    Also official documentation says so:

    If each array has an element with the same string key value, the latter will overwrite the former (different from array_merge_recursive).

    Source: http://www.yiiframework.com/doc/api/1.1/CMap#mergeArray-detail

    Try to determine the problem via print_r the result array and look at it inner structure. I think the problem is here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Yii, I have enabled APC caching through the config/main.php file: 'cache' => array(
i have a yii site that contains main layout. in this main layout file
Is there any extension to Yii which generates metrics for the project? I have
I'm creating a test application with Yii and have created my first migration. <?php
In a YII work, I have an init() function which checks whether the session
I'm working with yii framework forms and I have a form like this: <?php
I have a Yii dropdown which loads a table of cities, states, zipcodes, lat
I am finishing up a project in PHP with Yii and phing. Even though
I'm use Yii Framework. I have a named anchor <a name=projet>projet</a> in about.php page.
I'm writing an extension for the Yii framework which I have asked on here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.