为什么这个输出是空白的?

时间:2011-06-17 01:50:08

标签: php zend-framework gdata

我知道我必须做一些简单的错误。当我这样做时:

 echo '<pre>';
 print_r($event->when);
 echo '</pre>';

我明白了:

 Array
(
[0] => Zend_Gdata_Extension_When Object
    (
        [_rootElement:protected] => when
        [_reminders:protected] => 
        [_startTime:protected] => 2011-06-16T10:00:00.000-05:00
        [_valueString:protected] => 
        [_endTime:protected] => 2011-06-17T11:00:00.000-05:00
        [_rootNamespace:protected] => gd
        [_rootNamespaceURI:protected] => 
        [_extensionElements:protected] => Array
            (
            )

        [_extensionAttributes:protected] => Array
            (
            )

        [_text:protected] => 
        [_namespaces:protected] => Array
            (
                [atom] => Array
                    (
                        [1] => Array
                            (
                                [0] => http://www.w3.org/2005/Atom
                            )

                    )

                [app] => Array
                    (
                        [1] => Array
                            (
                                [0] => http://purl.org/atom/app#
                            )

                        [2] => Array
                            (
                                [0] => http://www.w3.org/2007/app
                            )

                    )

                [gd] => Array
                    (
                        [1] => Array
                            (
                                [0] => http://schemas.google.com/g/2005
                            )

                    )

                [openSearch] => Array
                    (
                        [1] => Array
                            (
                                [0] => http://a9.com/-/spec/opensearchrss/1.0/
                            )

                        [2] => Array
                            (
                                [0] => http://a9.com/-/spec/opensearch/1.1/
                            )

                    )

                [rss] => Array
                    (
                        [1] => Array
                            (
                                [0] => http://blogs.law.harvard.edu/tech/rss
                            )

                    )

            )

    )

)

我正试图通过这样做来获得startTime

$StartTime = $event->when->startTime;

但我没有得到任何东西。

然而,当我这样做时:

 pr($event->published);

我明白了:

Zend_Gdata_App_Extension_Published Object
(
[_rootElement:protected] => published
[_rootNamespace:protected] => atom
[_rootNamespaceURI:protected] => 
[_extensionElements:protected] => Array
    (
    )

[_extensionAttributes:protected] => Array
    (
    )

[_text:protected] => 2011-06-15T03:32:14.000Z
[_namespaces:protected] => Array
    (
        [atom] => Array
            (
                [1] => Array
                    (
                        [0] => http://www.w3.org/2005/Atom
                    )

            )

        [app] => Array
            (
                [1] => Array
                    (
                        [0] => http://purl.org/atom/app#
                    )

                [2] => Array
                    (
                        [0] => http://www.w3.org/2007/app
                    )

            )

    )

)

我可以这样做:

$dateAdded = $event->published->text;
echo $dateAdded;

我看到输出......

2 个答案:

答案 0 :(得分:2)

根据to the official Zend_Gdata_Extension_When documentation,有一种名为getStartTime()的方法会给你时间。

如果您执行$event->when[0]->getStartTime()$event->when[0]->startTime,您将获得开始时间。

答案 1 :(得分:1)

startTime被标记为受保护。你不能像你一样从外面引用它。该对象中必须有一个getter函数'getStartTime()'函数,允许您公开引用它。

编辑:它还返回一个对象数组 - 而不是单个对象,所以你需要引用它,如:$event[0]->getterFunction()或循环遍历数组,foreach访问单个对象循环