0

我对 PHP 很陌生,如果这是一个非常愚蠢的问题,我很抱歉。

我正在使用 cakePHP,我在一个方法中有以下代码/src/Controller/CommentsController.php

$comment = $this->Comments->get($id, [
    'contain' => []
]);

当我debug($comment)得到类似的东西时:

object(App\Model\Entity\Comment) {
    'new' => false,
    'accessible' => [
        'user_id' => true,
        'commentary' => true,
        'user' => true
    ],
    'properties' => [
        'id' => (int) 3,
        'user_id' => (int) 2,
        'commentary' => 'Hello World!',
        'created' => object(Cake\I18n\Time) {
            'time' => '2014-12-02T18:53:52+0000',
            'timezone' => 'UTC',
            'fixedNowTime' => false
        },
        'updated' => null
    ],
    'dirty' => [],
    'original' => [],
    'virtual' => [],
    'errors' => [],
    'repository' => 'Comments'
}

我需要将其与另一个变量进行比较'user_id''properties'但我不知道如何访问对象的属性$comment。我试过$comment->propertiesand $comment['properties'],但都返回null。您将如何访问这些属性?

4

0 回答 0