Php 如何在Yii框架中获取CActiveRecord中的特定行?

Php 如何在Yii框架中获取CActiveRecord中的特定行?,php,activerecord,yii,cactiverecord,Php,Activerecord,Yii,Cactiverecord,假设我有一张如下的唱片 $user = Users::model()->find('username = :x_username AND password = :x_password'); 使用者 -身份证 -用户名 -密码 登录时,我想检查用户的x_用户名、x_密码和此记录,我应该返回匹配的行。如何在CActiveRecord中做到这一点 我尝试了以下方法 $user = Users::model()->find('username = :x_username AND passw

假设我有一张如下的唱片

$user = Users::model()->find('username = :x_username AND password = :x_password');
使用者 -身份证 -用户名 -密码

登录时,我想检查用户的x_用户名、x_密码和此记录,我应该返回匹配的行。如何在CActiveRecord中做到这一点

我尝试了以下方法

$user = Users::model()->find('username = :x_username AND password = :x_password');
但它不起作用

怎么做?

试试这个

 $user = Users::model()->find('username = :x_username AND password = 
:x_password',array(':x_username'=>'myname',':x_password'=>'mypassword'));


在yii框架中进行登录管理。您应该使用UserIdentity组件。您需要在components文件夹下修改UserIdentity,如下所示

<?php


class UserIdentity extends CUserIdentity
{
    private $_id;

    public function authenticate()
    {

        $users=User::model()->find('LOWER(username)=?',array(strtolower($this->username)));
        if(!isset($users[$this->username]))
            $this->errorCode=self::ERROR_USERNAME_INVALID;
        else if($users[$this->username]!==$this->password)
            $this->errorCode=self::ERROR_PASSWORD_INVALID;
        else
        {
            $this->_id=$user->id;
            $this->username=$user->username;
            $this->errorCode=self::ERROR_NONE;
        }
        return !$this->errorCode;
    }
    public function getId()
    {
        return $this->_id;
    }
}

如何在find方法中传递参数值。看起来你错过了这些value@naveengoyal明白了谢谢你应该用