pungpoo / giix

Automatically exported from code.google.com/p/giix
0 stars 0 forks source link

I can't add more rules to Class.php #35

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Create a class using giix (e.g. Pedido)
2.Add a function rules() to model Pedido.php
3.Add a constraint

What is the expected output?
Data being saved according to previous rules (both BasePedido.php and 
Pedido.php)

What do you see instead?
When updating data nothing occur.
The following message is received in log.
Failed to set unsafe attribute "atividades" of "Pedido".

What version of giix are you using?
1.9.1

What is your stack (operating system, web server, DBMS, PHP version)?
Debian Squeeze, Apache2, Mysql, PHP5

What version of the Yii Framework are you using?
1.1.1

Any relevant additional software (opcode cache etc)?
Nope

Please paste the stack trace and the error message.
012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"dt_fim" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)
in /var/www/felipe/passagens/index.php (13)
2012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"atividades" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)
in /var/www/felipe/passagens/index.php (13)
2012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"trecho_ida" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)
in /var/www/felipe/passagens/index.php (13)
2012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"trecho_volta" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)
in /var/www/felipe/passagens/index.php (13)
2012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"dt_ida" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)
in /var/www/felipe/passagens/index.php (13)
2012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"dt_volta" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)
in /var/www/felipe/passagens/index.php (13)
2012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"hora_ida" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)
in /var/www/felipe/passagens/index.php (13)
2012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"hora_volta" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)
in /var/www/felipe/passagens/index.php (13)
2012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"justificativa" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)
in /var/www/felipe/passagens/index.php (13)
2012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"nome_projeto" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)
in /var/www/felipe/passagens/index.php (13)
2012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"idacao" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)
in /var/www/felipe/passagens/index.php (13)
2012/03/21 14:19:55 [warning] [application] Failed to set unsafe attribute 
"autorizador" of "Pedido".
in /var/www/felipe/passagens/protected/controllers/PedidoController.php (62)

Please attach your relevant source and configuration files and sql scripts.
BasePedido.php
    public function rules() {
        return array(
            array('idfavorecido, idsetor, num_memo, ano, passagens, diarias, evento, tipo_evento, dt_inicio, dt_fim, atividades, nome_projeto, idacao, autorizador', 'required'),
            array('idfavorecido, idsetor, num_memo, passagens, diarias', 'numerical', 'integerOnly'=>true),
            array('ano', 'length', 'max'=>4),
            array('evento', 'length', 'max'=>200),
            array('tipo_evento', 'length', 'max'=>7),
            array('trecho_ida, trecho_volta, hora_ida, hora_volta, nome_projeto, autorizador', 'length', 'max'=>45),
            array('idacao', 'length', 'max'=>20),
            array('dt_ida, dt_volta, justificativa', 'safe'),
            array('trecho_ida, trecho_volta, dt_ida, dt_volta, hora_ida, hora_volta, justificativa', 'default', 'setOnEmpty' => true, 'value' => null),
            array('idpedido, idfavorecido, idsetor, num_memo, ano, passagens, diarias, evento, tipo_evento, dt_inicio, dt_fim, atividades, trecho_ida, trecho_volta, dt_ida, dt_volta, hora_ida, hora_volta, justificativa, nome_projeto, idacao, autorizador', 'safe', 'on'=>'search'),
        );
    }

Pedido.php

    public function rules() {
        return array(
            array('ano', 'numerical', 'min'=>2011),
            array('dt_inicio','date','format'=>Yii::app()->locale->getDateFormat('medium')),
            array('dt_fim','date','format'=>Yii::app()->locale->getDateFormat('medium')),
            array('dt_ida','date','format'=>Yii::app()->locale->getDateFormat('medium')),
            array('dt_volta','date','format'=>Yii::app()->locale->getDateFormat('medium')),
        );
    }

Please provide any additional information below.
If I paste the rules in BasePedido.php it works fine.
I had not this problem till I add 2 new fields in the database and made all the 
necessary modifications... I guess.

Thanks in advance.

Original issue reported on code.google.com by fsc7m...@gmail.com on 21 Mar 2012 at 7:23

GoogleCodeExporter commented 8 years ago
Use code like this on your child class:

public function rules() {
    return array_merge(parent::rules(), array(
        array(...rule...),
    ));
}

Original comment by rodrigo.coelho@gmail.com on 21 Mar 2012 at 7:43

GoogleCodeExporter commented 8 years ago
Many thanks! It solved my problem. Sorry my ignorance.

Original comment by fsc7m...@gmail.com on 21 Mar 2012 at 8:41