2014-01-28 29 views
0

我试图做到这一点:CakePHP的使用ID的从发现(“清单”)阵列,而不是显示值

$customers = $this->Customer->find('list', array('conditions' => //some code)); 
$conditions = array('Event.customer_id' => $customers //here's the problem); 
$this->Event->find('all', ('conditions' => $conditions)); 

的$客户找到回报:

array(
     [id1] => "Cust name 1", 
     [id2] => "Cust name 2", 
     ... 
     [idn] => "Cust name n") 

而我需要在$ conditions条件下$ customers数组应该是客户ID列表以找到我需要的,而是使用显示值(例如“Cust name n”),以便find返回一个空的$ events变量。

如何在查找条件过滤器中使用数组索引而不是数组值?

我知道这可能很容易,但我真的被困在这里。

谢谢。

回答

1

你只需要改变这样的代码:

$customers = $this->Customer->find('list', array('conditions' => //filter)); 
$conditions = array('Event.customer_id' => array_keys($customers)); 
$this->Event->find('all', ('conditions' => $conditions)); 

请注意,您通过array_keys($customers)而不是简单的数组。这将以CakePHP可以使用的格式提取您需要的ID。