下面我有一个在CMSMS中的事件期间传递的对象参数的print_r输出。我是php和CMSMS的新手。我特别需要id为11(persontasked)的对象的值,但我不知道从哪里开始。看起来它是一个带有一些参数的对象,其中一个是一个对象(fielddefs),它包含数组,我需要的值也在一个对象中。有没有一种简单的方法来浏览这个结构?它总是位于同一个地方。
这是包含我需要的值的块(Jon Smith):
[storage:ArrayObject:private] => Array
(
[0] => Jon Smith
)
位于此对象的深处:
ListIt2Item Object ( [item_id] => 55 [alias] => test-email [title] => test email [position] => 7 [active] => 1 [create_time] => 2014-12-30 14:48:03 [modified_time] => 2014-12-30 19:56:46 [start_time] => [end_time] => [owner] => 5 [key1] => [key2] => [key3] => [fielddefs] => ListIt2FielddefArray Object ( [_parent_item:ListIt2FielddefArray:private] => ListIt2Item Object *RECURSION* [storage:ArrayObject:private] => Array ( [6] => listit2fd_SelectDateTime Object ( [id:ListIt2FielddefBase:private] => 6 [name:ListIt2FielddefBase:private] => Date [alias:ListIt2FielddefBase:private] => Time_Opened [description:ListIt2FielddefBase:private] => [type:ListIt2FielddefBase:private] => SelectDateTime [friendlytype:ListIt2FielddefBase:private] => Select DateTime [value:ListIt2FielddefBase:private] => ListIt2FielddefValue Object ( [storage:ArrayObject:private] => Array ( [0] => 12-30-2014 ) ) [originator:ListIt2FielddefBase:private] => ListIt2 [active:ListIt2FielddefBase:private] => 1 [disabled:ListIt2FielddefBase:private] => [path:ListIt2FielddefBase:private] => /home/public_html/modules/ListIt2/lib/fielddefs/SelectDateTime [position:ListIt2FielddefBase:private] => 0 [required:ListIt2FielddefBase:private] => 1 [options:ListIt2FielddefBase:private] => Array ( [date_format] => mm-dd-yy [format_type] => 1 [show_seconds] => 0 [size] => 20 [time_format] => HH:mm ) [caller:ListIt2FielddefBase:private] => [item_id:ListIt2FielddefBase:private] => 55 [parent_array:ListIt2FielddefBase:private] => ListIt2FielddefArray Object *RECURSION* [event_handler:protected] => ListIt2EventHandlerBase Object ( [_field:ListIt2EventHandlerBase:private] => listit2fd_SelectDateTime Object *RECURSION* ) ) [10] => listit2fd_Dropdown Object ( [id:ListIt2FielddefBase:private] => 10 [name:ListIt2FielddefBase:private] => Category [alias:ListIt2FielddefBase:private] => ticketcategory [description:ListIt2FielddefBase:private] => [type:ListIt2FielddefBase:private] => Dropdown [friendlytype:ListIt2FielddefBase:private] => Dropdown [value:ListIt2FielddefBase:private] => ListIt2FielddefValue Object ( [storage:ArrayObject:private] => Array ( [0] => Software Problems ) ) [originator:ListIt2FielddefBase:private] => ListIt2 [active:ListIt2FielddefBase:private] => 1 [disabled:ListIt2FielddefBase:private] => [path:ListIt2FielddefBase:private] => /home/public_html/modules/ListIt2/lib/fielddefs/Dropdown [position:ListIt2FielddefBase:private] => 3 [required:ListIt2FielddefBase:private] => 1 [options:ListIt2FielddefBase:private] => Array ( [options] => Software Problems Hardware Problems Request New Software Request New Hardware Other ) [caller:ListIt2FielddefBase:private] => [item_id:ListIt2FielddefBase:private] => 55 [parent_array:ListIt2FielddefBase:private] => ListIt2FielddefArray Object *RECURSION* [event_handler:protected] => ListIt2EventHandlerBase Object ( [_field:ListIt2EventHandlerBase:private] => listit2fd_Dropdown Object *RECURSION* ) ) [11] => listit2fd_Dropdown Object ( [id:ListIt2FielddefBase:private] => 11 [name:ListIt2FielddefBase:private] => Assign To [alias:ListIt2FielddefBase:private] => persontasked [description:ListIt2FielddefBase:private] => [type:ListIt2FielddefBase:private] => Dropdown [friendlytype:ListIt2FielddefBase:private] => Dropdown [value:ListIt2FielddefBase:private] => ListIt2FielddefValue Object ( [storage:ArrayObject:private] => Array ( [0] => Jon Smith ) ) [originator:ListIt2FielddefBase:private] => ListIt2 [active:ListIt2FielddefBase:private] => 1 [disabled:ListIt2FielddefBase:private] => [path:ListIt2FielddefBase:private] => /home/public_html/modules/ListIt2/lib/fielddefs/Dropdown [position:ListIt2FielddefBase:private] => 4 [required:ListIt2FielddefBase:private] => 1 [options:ListIt2FielddefBase:private] => Array ( [options] => Jon Smith Joan Smith ) [caller:ListIt2FielddefBase:private] => [item_id:ListIt2FielddefBase:private] => 55 [parent_array:ListIt2FielddefBase:private] => ListIt2FielddefArray Object *RECURSION* [event_handler:protected] => ListIt2EventHandlerBase Object ( [_field:ListIt2EventHandlerBase:private] => listit2fd_Dropdown Object *RECURSION* ) ) ) ) )
答案 0 :(得分:1)
您遇到的问题是storage
属性私有,因此无法从ListIt2FielddefArray对象的实例外部访问。
您需要一个getter方法来访问该值。
它应该类似于:
<?php
$myobject->get('myval');
//or
$myobject->getStorage();
?>
基本上,必须有可公开访问的内容,以便您访问这些值。
如果你发布这些课程的实际代码,它会让我们更好地了解你的选择。
答案 1 :(得分:1)
我认为print_r让它看起来比它实际上要复杂得多。我能够得到这个价值:
$itemobject = $params['item_object'];
$itemobjectArray = (array)$itemobject;
$fielddefsArray=$itemobjectArray['fielddefs'];
$output = $fielddefsArray[11];`enter code here`
答案 2 :(得分:0)
即使打印为完整对象。
它已实现,因此您可以使用别名直接访问字段:
echo $item->persontasked; //this should print "Jon Smith"
public function __get($key)
{
if(isset($this->fielddefs[$key]))
return $this->fielddefs[$key]->GetValue();
}