Cakephp 如何按值查找 id

Cakephp how to find id by value

如何在 CakePHP 中编写此语法:

示例:

$userID = "SELECT user_id FROM customers WHERE phone = '88888888' ";

喜欢:

$user = $this->Customer->find('first', array('conditions' => array(
             'Customer.user_id WHERE phone' => '88888888')));

我想找到 user_id,其中 phone 数字具有特定值

您尝试做的事情非常基础,您应该阅读 find() 函数的文档。

$user = $this->Customer->find('first',  array(
    // You specify which field(s) you want
    'fields' => array('user_id'),
    // You add the condition(s)
    'conditions' => array('Customer.phone' => '88888888'),
));

您可以在这里使用cakephp 魔术功能。例如: $user = $this->Customer->findByPhone('8888888');