问题
On local server it works, but when I try to login on production server I get this message:
PHP Notice – yii\base\ErrorException
Array to string conversion
1. in /var/www/html/vendor/yiisoft/yii2/web/User.php at line 240
2. in /var/www/html/vendor/yiisoft/yii2/web/User.php – yii\base\ErrorHandler::handleError(8, 'Array to string conversion', '/var/www/html/vendor/yiisoft/yii...', 240, ...) at line 240
3. in /var/www/html/common/models/LoginForm.php – yii\web\User::login(common\models\User, 2592000) at line 59
4. in /var/www/html/frontend/controllers/SiteController.php – common\models\LoginForm::login() at line 81
Files on local and production servers are the same.
回答1:
Line 240 from yii2/web/User.php is
$log = "User '$id' logged in from $ip with duration $duration.";
So see if $id or $ip or $duration is an array. You are doing something wrong someplace.
Can you post what $_SERVER['REMOTE_ADDR'] is?
回答2:
It is happening due to the id field in the user database model is not a primary key. Simply add the PK constraint to user->id filed from the database.
From DB console:
ALTER TABLE `user` ADD PRIMARY KEY(`id`);
Or any visual tools like phpMyAdmin there is a primary key add functionality from the "Structure" tab.
来源:https://stackoverflow.com/questions/27681505/login-on-production-server-doesnt-work