Error reporting

I am making a user confirmation action.

The confirmation itself works fine, but I am trying to make something like this, to report errors:




if (sizeof($usuario) > 0) {

	if (md5($usuario->email) == $id) {

		$usuario->activo = 1;

		$usuario->codigoconfirmacion = '';

		$usuario->save();

		$this->errorCode = self::ERROR_NONE;

	} else {

		$this->errorCode = self::ERROR_INVALID_USER;

	}

} else {

	$this->errorCode = self::ERROR_USER_NOT_FOUND;

}



But when I run it, I get this error:




Fatal error: Undefined class constant 'ERROR_USER_NOT_FOUND' in /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/controllers/UsuarioController.php on line 203



The line 203 is:




$this->errorCode = self::ERROR_USER_NOT_FOUND;



I followed the example in the UserIdentity component, but I can’t find where these constants are defined or how.

Can you help me with this?

Thank you.

The class constants used by the UserIdentity class are defined in CUserIdentity or CWebuser, you must defined those constants that you are trying to use in order for it to work.

Thanks jayrules, but I’ve searched everywhere and I can’t find where or how these variables are defined.

However, I took a look at the Blog tutorial, where the Published Statuses (?) are defined and I did something similar.

Now I don’t get the error I reported before, but now I get:




CException


Description


Property "UsuarioController.errorCode" is not defined.


Source File


/Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/controllers/UsuarioController.php(206)


00194:             $usuario = usuario::model()->find($criteria);

00195:             if (sizeof($usuario) > 0) {

00196:                 if (md5($usuario->email) == $id) {

00197:                     $usuario->activo = 1;

00198:                     $usuario->codigoconfirmacion = '';

00199:                     $usuario->save();

00200:                     $this->errorCode = self::ERROR_NONE;

00201:                 } else {

00202:                     $this->errorCode = self::ERROR_INVALID_USER;

00203:                     //echo "No se puede confirmar usuario";

00204:                 }

00205:             } else {

00206:                 $this->errorCode = self::ERROR_USER_NOT_FOUND;

00207:                 //echo "No encontre al usuario";

00208:             }

00209:             $this->render('confirmacion',array('model'=>$usuario));

00210:         } else {

00211:             throw new CHttpException(404,'La página solicitada no existe.');

00212:         }

00213:     }

00214: }



What should I do now?

Thank you.

errorCode is not a property of the controller hence that error message. even if you fix that you will still get the errors you got previously. define your class properties and class constants like




<?php


class UsarioController extends CController

{

    public $errorCode;

    const ERROR_NONE = 0;

    const ERROR_INVALID_USER = 2;

    const ERROR_USER_NOT_FOUND = 4;

    ...............



and those values set for the constants must by no means be considered as standard. you can set them to whatever value you want etc


const ERROR_NONE = 'No error was found';