Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

independent db for an module #15874

Closed
rezvania opened this issue Mar 11, 2018 · 2 comments
Closed

independent db for an module #15874

rezvania opened this issue Mar 11, 2018 · 2 comments
Labels

Comments

@rezvania
Copy link

rezvania commented Mar 11, 2018

Hello Yii developers :)

Im new in yii freamwork, I want to have a independent database for my module, so I create a db config in my module like this:

1-first I create db.php file that return db config

<?php
/**
 * Created by PhpStorm.
 * User: Rezvania
 * Date: 3/10/2018
 * Time: 11:31 AM
 */
return[
    'class'=>'yii\db\Connection',
    'dsn'=>'mysql:host=localhost;dbname=db_entry_mdu',
    'username'=>'root',
    'password'=>'',
    'charset'=>'utf8',
    'tablePrefix'=>'tbl_entry_mdu_'
];

2-so i create config file that modify my module configs

`<?php
/**
 * Created by PhpStorm.
 * User: Rezvania
 * Date: 3/10/2018
 * Time: 11:30 AM
 */
$db=require __DIR__.'/db.php';
return[

    'defaultRoute'=>'entry',
  'components'=>[
      'db'=>$db,
  ]

];`

3-finaly I set that in my Module class

`<?php
/**
 * Created by PhpStorm.
 * User: Rezvania
 * Date: 3/10/2018
 * Time: 11:26 AM
 */

namespace app\modules\entry;
use yii\base\Module;
use yii;
class EntryModule extends Module
{
    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub
        \Yii::configure($this,require __DIR__.'/config/config.php');

    }
}
`

now when I try to use of tables data I get this error:

yii\base\ErrorException: Exception (Invalid Configuration) 'yii\base\InvalidConfigException' with message 'The table does not exist: {{%user}}'

in D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\db\ActiveRecord.php:353

Stack trace:
#0 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\db\ActiveRecord.php(384): yii\db\ActiveRecord::getTableSchema()
#1 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\db\BaseActiveRecord.php(491): yii\db\ActiveRecord->attributes()
#2 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\db\BaseActiveRecord.php(288): yii\db\BaseActiveRecord->hasAttribute('uname')
#3 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\helpers\BaseHtml.php(2189): yii\db\BaseActiveRecord->__get('uname')
#4 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\helpers\BaseHtml.php(1319): yii\helpers\BaseHtml::getAttributeValue(Object(app\modules\entry\models\Entry), 'uname')
#5 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\helpers\BaseHtml.php(1373): yii\helpers\BaseHtml::activeInput('text', Object(app\modules\entry\models\Entry), 'uname', Array)
#6 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\widgets\ActiveField.php(404): yii\helpers\BaseHtml::activeTextInput(Object(app\modules\entry\models\Entry), 'uname', Array)
#7 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\widgets\ActiveField.php(204): yii\widgets\ActiveField->textInput()
#8 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\widgets\ActiveField.php(176): yii\widgets\ActiveField->render()
#9 D:\Xampp\htdocs\basic\modules\entry\views\entry\index.php(15): yii\widgets\ActiveField->__toString()
#10 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\View.php(336): require('D:\Xampp\htdocs...')
#11 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\View.php(254): yii\base\View->renderPhpFile('D:\Xampp\htdocs...', Array)
#12 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\View.php(156): yii\base\View->renderFile('D:\Xampp\htdocs...', Array, Object(app\modules\entry\controllers\EntryController))
#13 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\Controller.php(384): yii\base\View->render('index', Array, Object(app\modules\entry\controllers\EntryController))
#14 D:\Xampp\htdocs\basic\modules\entry\controllers\EntryController.php(33): yii\base\Controller->render('index', Array)
#15 [internal function]: app\modules\entry\controllers\EntryController->actionIndex()
#16 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#17 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#18 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('', Array)
#19 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('entry', Array)
#20 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#21 D:\Xampp\htdocs\basic\web\index.php(12): yii\base\Application->run()
#22 {main} in D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\ErrorHandler.php:317
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(256, 'Exception (Inva...', 'D:\Xampp\htdocs...', 317, Array)
#1 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\ErrorHandler.php(317): trigger_error('Exception (Inva...', 256)
#2 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\widgets\ActiveField.php(178): yii\base\ErrorHandler::convertExceptionToError(Object(yii\base\InvalidConfigException))
#3 D:\Xampp\htdocs\basic\modules\entry\views\entry\index.php(15): yii\widgets\ActiveField->__toString()
#4 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\View.php(336): require('D:\Xampp\htdocs...')
#5 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\View.php(254): yii\base\View->renderPhpFile('D:\Xampp\htdocs...', Array)
#6 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\View.php(156): yii\base\View->renderFile('D:\Xampp\htdocs...', Array, Object(app\modules\entry\controllers\EntryController))
#7 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\Controller.php(384): yii\base\View->render('index', Array, Object(app\modules\entry\controllers\EntryController))
#8 D:\Xampp\htdocs\basic\modules\entry\controllers\EntryController.php(33): yii\base\Controller->render('index', Array)
#9 [internal function]: app\modules\entry\controllers\EntryController->actionIndex()
#10 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#11 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#12 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('', Array)
#13 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('entry', Array)
#14 D:\Xampp\htdocs\basic\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#15 D:\Xampp\htdocs\basic\web\index.php(12): yii\base\Application->run()
#16 {main}

@yii-bot
Copy link

yii-bot commented Mar 11, 2018

Thank you for your question.
In order for this issue tracker to be effective, it should only contain bug reports and feature requests.

We advise you to use our community driven resources:

If you are confident that there is a bug in the framework, feel free to provide information on how to reproduce it. This issue will be closed for now.

This is an automated comment, triggered by adding the label question.

@SilverFire
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants