0

ユーザー名またはパスワードが間違っていると、このエラーが発生しました。正しいユーザー名とパスワードで正常に実行されます。... 内の非オブジェクトでメンバー関数 count() を呼び出します。

私のコードは

public function executeLogin(sfWebRequest $request)
{
    $this->form = new loginForm();

    if ($request->isMethod('post'))
    {
        $this->form->bind($request->getParameter('login'));
        if ($this->form->isValid())
        {
            $unm=$this->form->getValue('username');
            $pwd=$this->form->getValue('password');
            $q = Doctrine_Query::create()
            ->select('id')
            ->from('login')
            ->andWhere('username = ?', $unm)
            ->andWhere('password = ?', $pwd);
            $q->execute();
            $result = $q->fetchOne();
            if ($result->count() > 0) 
            {            
                $this->getUser()->setAuthenticated(true);
                $this->getUser()->addCredential('user');
                $this->redirect('user/index');
            } 
            else 
            {
                $this->redirect('user/login');
            }   
        }
    }
}
4

1 に答える 1

1

$result 値に NULL 値があります。最初に確認する必要があります。条件を次のように変更しましょう。

if ($result && $result->count() > 0) {...}

あるいは

if ($result) {...}
于 2013-10-31T10:50:40.583 に答える