小编Jun*_*Jun的帖子

设置时区不会更改CakePHP 3.x中的显示时间

我正在使用CakePHP 3.x并且有几个小时的问题.

我的数据库(MySQL)有正确的小时数.当我的应用程序显示这些时间时,我有几个小时的UTC而不是我的记录.换句话说,我在我的数据库中记录了10:00,在我的网站上显示了08:00

据Cookbook说,我试图改变

date_default_timezone_set('UTC');
Run Code Online (Sandbox Code Playgroud)

date_default_timezone_set('Europe/Paris');
Run Code Online (Sandbox Code Playgroud)

config/bootstrap.php中

但我还有时间在UTC.也许我错过了什么?

提前致谢

timezone cakephp cakephp-3.0

7
推荐指数
2
解决办法
1万
查看次数

CakePHP 3.x 中的多个 ownTo() 关联

我正在使用 CakePHP 3.x。
我的问题是:同一个外键是否可以有多个belongsTo() 关联?

这是我的问题:
我的表中有三个字段使用相同的外键。

在模型表中,我这样使用belongsTo()关联:

$this->belongsTo('Pilotes', [
    'className' => 'Users',
    'foreignKey' => 'pilote',
    'propertyName' => 'pilote_user'
]);

$this->belongsTo('Verificateurs', [
    'className' => 'Users',
    'foreignKey' => 'no_user',
    'propertyName' => 'verificateur_user'
]);

$this->belongsTo('Users', [
    'className' => 'Users',
    'foreignKey' => 'no_user',
    'propertyName' => 'user'
]);
Run Code Online (Sandbox Code Playgroud)

但是当我调试我的实体时,前两个字段仅包含外键,最后一个字段很好。

查询:

public function view($id = null)
{
    $demande = $this->Demandes->get($id, [
        'contain' => ['Users']
    ]);
    $this->set('demande', $demande);
    $this->set('_serialize', ['demande']);
}
Run Code Online (Sandbox Code Playgroud)

这是 debug() 的输出:

object(App\Model\Entity\Demande) {
'new' => false,
'accessible' => [
    'pilote' => true,
    'verificateur' …
Run Code Online (Sandbox Code Playgroud)

cakephp cakephp-3.0

1
推荐指数
1
解决办法
6484
查看次数

标签 统计

cakephp ×2

cakephp-3.0 ×2

timezone ×1