在我的控制器里我有
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
答案 0 :(得分:0)
尝试
if(isset($username) && trim($username)!=='')
{
$exist = $user_obj->checkUsernameExist($username);
if($exist == '1')
{
$form->getElement('username')->addError('This username exists.');
$form->markAsError();
}
}
答案 1 :(得分:0)
您的代码看起来正确,您需要提供更多行代码供审核。