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

Controller id is null in model #15725

Closed
fmartiner opened this issue Feb 21, 2018 · 8 comments
Closed

Controller id is null in model #15725

fmartiner opened this issue Feb 21, 2018 · 8 comments

Comments

@fmartiner
Copy link

fmartiner commented Feb 21, 2018

What steps will reproduce the problem?

I have 2 different controller and in login model i want to switch to corret db in base at controller->id

class LoginModel extends \yii\db\ActiveRecord{
public static function getDb() {
		if(Yii::$app->controller->id==="controller1"){
			return Yii::$app->db1;
		} else if(Yii::$app->controller->id==="controller2"){
			return Yii::$app->db2;
		}
	}

}

What's expected?

Trying to get property of non-object

Yii::$app->controller = NULL

What do you get instead?

No exception and Yii::$app->controller->id = controller1

Additional info

In yii2 version 2.0.7 the problem not exist.

Q A
Yii vesion 2.0.15-dev
PHP version 5.5.17
Operating system Windows Server 2008 R2
@SilverFire SilverFire added the status:to be verified Needs to be reproduced and validated. label Feb 21, 2018
@SilverFire SilverFire added this to the 2.0.14.1 milestone Feb 21, 2018
@SilverFire SilverFire added the type:bug Bug label Feb 21, 2018
@samdark
Copy link
Member

samdark commented Feb 21, 2018

@fmartiner would you please check 2.0.13?

@samdark samdark modified the milestones: 2.0.14.1, 2.0.15 Feb 23, 2018
@yii-bot
Copy link

yii-bot commented Feb 23, 2018

Thanks for posting in our issue tracker.
In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

@samdark
Copy link
Member

samdark commented Feb 23, 2018

Unable to reproduce with the info given.

@fmartiner
Copy link
Author

fmartiner commented Feb 26, 2018

@samdark Same problem with version 2.0.13

All my model extends the LoginModel:

class Fsuser extends \app\models\LoginModel

I receive the error:

exception 'yii\base\ErrorException' with message 'Trying to get property of non-object' in \basic_14\models\Loginmodel.php:20
Stack trace:
#0 \basic_14\models\Loginmodel.php(20): yii\base\ErrorHandler->handleError(8, 'Trying to get p...', '\basic...', 20, Array)
#1 \basic_14\vendor\yiisoft\yii2\db\ActiveRecord.php(348): app\models\Loginmodel::getDb()
#2 \basic_14\vendor\yiisoft\yii2\db\ActiveRecord.php(374): yii\db\ActiveRecord::getTableSchema()
#3 \basic_14\vendor\yiisoft\yii2\db\ActiveRecord.php(177): yii\db\ActiveRecord::primaryKey()
#4 \basic_14\vendor\yiisoft\yii2\db\BaseActiveRecord.php(112): yii\db\ActiveRecord::findByCondition('usr')
#5 \basic_14\models\Fsuser.php(99): yii\db\BaseActiveRecord::findOne('usr')
#6 \basic_14\vendor\yiisoft\yii2\web\User.php(677): app\models\Fsuser::findIdentity('usr')
#7 \basic_14\vendor\yiisoft\yii2\web\User.php(192): yii\web\User->renewAuthStatus()
#8 \basic_14\vendor\yiisoft\yii2\web\User.php(344): yii\web\User->getIdentity()
#9 \basic_14\vendor\yiisoft\yii2\base\Component.php(139): yii\web\User->getIsGuest()
#10 \basic_14\vendor\yiisoft\yii2-debug\src\panels\UserPanel.php(79): yii\base\Component->__get('isGuest')
#11 \basic_14\vendor\yiisoft\yii2\base\BaseObject.php(109): yii\debug\panels\UserPanel->init()
#12 [internal function]: yii\base\BaseObject->__construct(Array)
#13 \basic_14\vendor\yiisoft\yii2\di\Container.php(383): ReflectionClass->newInstanceArgs(Array)
#14 \basic_14\vendor\yiisoft\yii2\di\Container.php(156): yii\di\Container->build('yii\debug\panel...', Array, Array)
#15 \basic_14\vendor\yiisoft\yii2\BaseYii.php(349): yii\di\Container->get('yii\debug\panel...', Array, Array)
#16 \basic_14\vendor\yiisoft\yii2-debug\src\Module.php(177): yii\BaseYii::createObject(Array)
#17 \basic_14\vendor\yiisoft\yii2-debug\src\Module.php(149): yii\debug\Module->initPanels()
#18 \basic_14\vendor\yiisoft\yii2\base\BaseObject.php(109): yii\debug\Module->init()
#19 \basic_14\vendor\yiisoft\yii2\base\Module.php(158): yii\base\BaseObject->__construct(Array)
#20 [internal function]: yii\base\Module->__construct('debug', Object(yii\web\Application), Array)
#21 \basic_14\vendor\yiisoft\yii2\di\Container.php(375): ReflectionClass->newInstanceArgs(Array)
#22 \basic_14\vendor\yiisoft\yii2\di\Container.php(156): yii\di\Container->build('yii\debug\Modul...', Array, Array)
#23 \basic_14\vendor\yiisoft\yii2\BaseYii.php(349): yii\di\Container->get('yii\debug\Modul...', Array, Array)
#24 \basic_14\vendor\yiisoft\yii2\base\Module.php(427): yii\BaseYii::createObject(Array, Array)
#25 \basic_14\vendor\yiisoft\yii2\base\Application.php(315): yii\base\Module->getModule('debug')
#26 \basic_14\vendor\yiisoft\yii2\web\Application.php(69): yii\base\Application->bootstrap()
#27 \basic_14\vendor\yiisoft\yii2\base\Application.php(273): yii\web\Application->bootstrap()
#28 \basic_14\vendor\yiisoft\yii2\base\BaseObject.php(109): yii\base\Application->init()
#29 \basic_14\vendor\yiisoft\yii2\base\Application.php(206): yii\base\BaseObject->__construct(Array)
#30 \basic_14\web\index.php(12): yii\base\Application->__construct(Array)
#31 {main}

@samdark
Copy link
Member

samdark commented Feb 26, 2018

What's LoginModel?

@samdark
Copy link
Member

samdark commented Feb 26, 2018

Trace looks like it's debug panel, is it?

@fmartiner
Copy link
Author

Loginmodel is a generic model who i use for switch db in base of controller id.
Other models extends Loginmodel. Any find use the getDb in loginmodel

Yes trace is the stacktrace in the debug page

@yii-bot
Copy link

yii-bot commented Feb 26, 2018

Issue moved to yiisoft/yii2-debug#306

@yii-bot yii-bot closed this as completed Feb 26, 2018
@cebe cebe removed this from the 2.0.16 milestone May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants