嘿伙计们我试图从我的events_controller.php文件中的数组中获取值。 事件属于实体和实体hasMany事件。我需要这个值来执行一些其他逻辑,但我真的卡住了,我知道这应该是一件容易的事情。
我试图从这个数组中获取Entity.user_id的值。
Array
(
[Event] => Array
(
[id] => 19
[entity_id] => 8
[name] => new event
[time_start] => 2011-02-26 19:09:00
[time_end] => 2011-02-26 19:09:00
[dateStart] => 0000-00-00
[dateEnd] => 0000-00-00
[description] => jgiuguygo
[ageRange] => 67
)
[Entity] => Array
(
[id] => 8
[user_id] => 14
[location_id] => 15
[type] => EVENT
)
[Eventfeedback] => Array
(
)
)
使用此代码获得的上述矩阵:
$value = $this->Event->read();
pr($value);
现在这是我能得到的......
Array
(
[Entity] => Array
(
[user_id] => 14
)
[Event] => Array
(
[id] => 19
)
[Eventfeedback] => Array
(
)
)
使用此代码
$value = $this->Event->read('Entity.user_id');
pr($value);
最后一次尝试我得到了这个数组
Array
(
[Entity] => Array
(
[id] => 1
[user_id] => 11
[location_id] => 8
[type] => sdfsdfdsf
)
[User] => Array
(
[id] => 11
[firstName] => luis
[lastName] => pooya
[username] => admin
[password] => 94c882c8506497a9f031ca5a4db6d0143c97fe45
[role] => admin
[email] => some
)
[Location] => Array
(
[id] => 8
[name] => First Nation University of Canada
[xCoordinate] => 0
[yCoordinate] => 0
)
[Establishment] => Array
(
)
[Event] => Array
(
)
[Vmachine] => Array
(
)
)
使用此代码
$value = $this->Event->Entity->find('user_id');
pr($value);
希望有人可以帮助我。在此先感谢.Luis
答案 0 :(得分:2)
我不确定我是否正确理解你。但是在你的例子中获得user_id就像
$value = $this->Event->read('Entity.user_id');
pr($value['Entity']['user_id']);
答案 1 :(得分:2)
$event = $this->Event->read();
$userId = $event['Entity']['user_id'];