2011-02-27 23 views
1

嘿家伙我想从我的events_controller.php文件中获取数组的值。 事件belongsTo实体和实体hasMany事件。我需要这个价值来执行一些其他的逻辑,但我真的坚持,我知道这应该是一件容易的事情。在数组中找到值cakephp

我想从这个数组中获取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); 

希望有人能帮助我。在此先感谢。路易斯

回答

2

我不确定我是否正确理解了你。但要获得USER_ID在你的例子是像

+0

谢谢您的帮助。有效 – allegjdm93 2011-03-01 08:47:18

2
$event = $this->Event->read(); 
$userId = $event['Entity']['user_id'];