0

我正在尝试测试用户名是否已经存在。但总是返回“用户名存在”:

   if (!isset($_POST['usuario'])) {
    /* Parameters not pass */
    exit("{'success': false, 'msg': 'No hay parametros.'}");
   }

   /* Search a user with username == $_POST['usuario'] */
   $usuarioCohincidente = UsuariosQuery::create()
                          ->filterByNombreusuario($_POST['usuario'])
                          ->find();

   if($usuarioCohincidente->isEmpty()){
       /* Username is available */
       exit("{'success': false, 'msg':'Usuario inexistente.'}");
   }else{
      /* Username is not available */
      exit("{'success': true, 'msg': 'Usuario existente, por favor, seleccione otro      nombre para el usuario.'}");
   }

任何想法 ?。

4

1 回答 1

1

首先你应该尝试

$usuarioCohincidente = UsuariosQuery::create() ->filterByNombreusuario($_POST['usuario']) ->findOne();

不是find()因为它不会返回对象而是包含对象的数组。

不要检查我的方法isEmpty(),使用if($usuarioCohincidente == null).

总而言之,请包括var_dump您的对象,以确保您做的是正确的事情。

于 2014-04-30T11:00:44.290 回答