0

在我的控制器中,我有

if(isset($username) && trim($username)!=='')
{
    $exist  = $user_obj->checkUsernameExist($username);
        if($exist   ==  '1')
        {
            $form->getElement('username')->addError('This username exists.');
        }
}
if ($form->isValid($_POST) ) {
$user_obj->insertUser($_POST);
$this->_helper->flashMessenger->addMessage('User Added Successfully.');
 $this->_redirect('/users/usersadministration/');
 exit();    
}else { //echo 'failure';
     //print_r($form->getErrors());
 }

但即使$exist值为1

4

2 回答 2

0

尝试

if(isset($username) && trim($username)!=='')
{
    $exist  = $user_obj->checkUsernameExist($username);
        if($exist   ==  '1')
        {
            $form->getElement('username')->addError('This username exists.');
            $form->markAsError();
        }
}
于 2012-11-09T09:19:56.157 回答
0

您的代码看起来正确,您需要提供更多代码行以供审核。

于 2012-11-09T09:28:03.540 回答