save() doesn't work in an action

Hi, save() doesn’t work in actionActivate and I don’t know why. Anyone can tell me how to debug it?

my controller’s action:


public function actionActivate()

        {

                        $model=$this->loadUtenti(); // loadUtenti loads data form utenti table where id=$_GET['id']

/* if I do, here, a var_dump($model); it display data */

                        $model->attivo = 'true'; // if I do, here, echo $model->attivo it displays "true" 

                if ($model->save())  // no, it doesn't work even if it works in other actions

                        $this->redirect(array('admin'));

                        else throw new CHttpException(400,'Problemi con la richiesta'); 

}



my view:


echo Chtml::link('Attiva',array('activate','id'=>$model->id_utente));



model is default one created by yiic shell

log in application.log ( ‘levels’=>‘error,warning,trace,info’,):

as you can see there is not “UPDATE” statement… :(((


2009/09/07 13:35:14 [trace] [system.web.CModule] Loading "log" application component

2009/09/07 13:35:14 [trace] [system.web.CModule] Loading "request" application component

2009/09/07 13:35:14 [trace] [system.web.CModule] Loading "urlManager" application component

2009/09/07 13:35:14 [trace] [system.web.filters.CFilterChain] Running filter UtentiController.filteraccessControl()

2009/09/07 13:35:14 [trace] [system.web.CModule] Loading "user" application component

2009/09/07 13:35:14 [trace] [system.web.CModule] Loading "session" application component

2009/09/07 13:35:14 [trace] [system.web.CModule] Loading "db" application component

2009/09/07 13:35:14 [trace] [system.db.CDbConnection] Opening DB connection

2009/09/07 13:35:14 [trace] [system.db.CDbCommand] Querying SQL: SHOW COLUMNS FROM `utenti`

2009/09/07 13:35:14 [trace] [system.db.CDbCommand] Querying SQL: SHOW CREATE TABLE `utenti`

2009/09/07 13:35:14 [trace] [system.db.ar.CActiveRecord] utenti.findByPk()

2009/09/07 13:35:14 [trace] [system.db.CDbCommand] Querying SQL: SELECT * FROM `utenti` WHERE `utenti`.`id_utente`=59 LIMIT 1

2009/09/07 13:35:14 [trace] [system.web.CModule] Loading "coreMessages" application component

2009/09/07 13:35:14 [error] [exception.CHttpException.400] exception 'CHttpException' with message 'Problemi con la richiesta' in /var/www/dibevit/dibevit/protected/controllers/UtentiController.php:132

Stack trace:

#0 /var/www/dibevit/framework/web/actions/CInlineAction.php(32): UtentiController->actionActivate()

#1 /var/www/dibevit/framework/web/CController.php(300): CInlineAction->run()

#2 /var/www/dibevit/framework/web/filters/CFilterChain.php(129): CController->runAction(Object(CInlineAction))

#3 /var/www/dibevit/framework/web/filters/CFilter.php(41): CFilterChain->run()

#4 /var/www/dibevit/framework/web/CController.php(952): CFilter->filter(Object(CFilterChain))

#5 /var/www/dibevit/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#6 /var/www/dibevit/framework/web/filters/CFilterChain.php(126): CInlineFilter->filter(Object(CFilterChain))

#7 /var/www/dibevit/framework/web/CController.php(283): CFilterChain->run()

#8 /var/www/dibevit/framework/web/CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)

#9 /var/www/dibevit/framework/web/CWebApplication.php(332): CController->run('activate')

#10 /var/www/dibevit/framework/web/CWebApplication.php(120): CWebApplication->runController('utenti/activate...')

#11 /var/www/dibevit/framework/base/CApplication.php(133): CWebApplication->processRequest()

#12 /var/www/dibevit/dibevit/index.php(11): CApplication->run()

#13 {main} REQUEST_URI=/dibevit/index.php/utenti/activate/id/59.html

2009/09/07 13:35:14 [trace] [system.web.CModule] Loading "errorHandler" application component



Any help?

save() validates the model. It seems that the validation failed. If you do not want a validation you can call save(false)

I don’t know what your table column types are, so I am just guessing here:

You are doing this: $model->attivo = ‘true’;

‘true’ is a string, maybe your attivo column is integer?

So maybe try $model->attivo = true; or $model->attivo = 1;

Dave,

you->saved($myLife)

:smiley:

Hehe thats funny,

anyway you should take a look at the reason why the validation fails :)

how? is there away to log it? function rules() seems ok to me:


 public function rules()

        {

                return array(

                        array('ragione_sociale,insegna,comune,provincia,indirizzo,cap,piva,tipologia_alt,nome,cognome,distributore,password','required'),

                        array('ragione_sociale','length','max'=>255),

                        array('insegna','length','max'=>255),

                        array('comune','length','max'=>255),

                        array('provincia','length','max'=>4),

                        array('indirizzo','length','max'=>255),

                        array('cap','length','max'=>5),

                        array('piva','length','max'=>11),

                        array('web','length','max'=>255),

                        array('tipologia_alt','length','max'=>255),

                        array('nome','length','max'=>255),

                        array('cognome','length','max'=>255),

                        array('email','length','max'=>255),

                        array('telefono','length','max'=>25),

                        array('distributore','length','max'=>255),

                        array('password','length','max'=>32),

                        array('attivo','length','max'=>5), // <-- this is the modified field 

                        array('password2','length','max'=>32),

                        array('password','compare','compareAttribute'=>'password2'),

                );

        }



I guess password2 will not be there if you retrieve your model from the database.

If that is the only difference you can call save(false) without worry about. I just wanted to say that you should know why you need to call save(false) instead of just calling it because it works :)

check your field before you insert/update database.