【发布时间】:2015-12-27 13:28:38
【问题描述】:
我有 User 表与 zerofill 主要 id:
CREATE TABLE `user` (
`id` int(5) unsigned zerofill NOT NULL AUTO_INCREMENT,
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB
我的User 模型看起来像:
class User extends ActiveRecord implements IdentityInterface
{
public static function tableName()
{
return '{{%user}}';
}
public static function findIdentity($id)
{
$identity = static::findOne(['id' => (int)$id]);
var_dump($identity); //zeros are lost here
exit;
}
public static function findIdentityByAccessToken($token, $type = null)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
public function getId()
{
return $this->getPrimaryKey();
}
public function getAuthKey()
{
return $this->auth_key;
}
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
}
Active Record 将 id 转换为 int 所以我得到:1 for 00001; 2 用于00002 等,但我想保留零并将id 视为string。
在 x32 系统上一切正常,但我们转移到了 x64。如何强制 Active Record 将id 视为string?
【问题讨论】:
标签: php activerecord yii2