Cakephp如何按值查找id

时间:2017-11-17 16:50:32

标签: php sql cakephp syntax cakephp-2.0

如何在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,其中电话号码具有特定值

2 个答案:

答案 0 :(得分:1)

您尝试做的事情非常基础,您应该阅读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'),
));

答案 1 :(得分:1)

你可以在这里使用cakephp魔术功能。例如:  npm install packagename --save-dev