【问题标题】:cakephp compare array with database fieldscakephp 将数组与数据库字段进行比较
【发布时间】:2013-09-16 09:57:30
【问题描述】:

我正在用 cakePHP 开发一个应用程序。我应该获取一个数组 $data,其中包含用户名和密码(非散列),并将其与表客户中的所有行进行比较,如果它与任何行匹配,我将发回一条消息说用户找到。这是我写的代码:

$data = $this->request->input('json_decode');
$data = $this->Customer->findByUsernameAndPassword('data.firstname','data.lastname');

if ($data) { ...message...}

现在我知道数据设置正确,我知道问题在于比较参数“data.firstname”等。正确的语法应该是什么?

【问题讨论】:

  • 您不应该将参数作为变量传递给 findByUsernameAndPassword 吗?在此示例中,您传递了两个字符串“data.firstname”和“data.lastname”。
  • 是的,理想情况下我会这样做,但我将 JSON 数据接收到 $data 数组中,如下所示: stdClass Object ( [username] => john [password] => merriweather ) 我不知道如何将此与数据库中的字段进行比较...正确的命令是什么?非常感谢您的回复!

标签: php arrays cakephp


【解决方案1】:

试试:

$data = $this->Customer->findByUsernameAndPassword($data['username'],$data['password']);

【讨论】:

    猜你喜欢
    • 2011-12-31
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    相关资源
    最近更新 更多