E
E
EVOSandru62015-08-18 14:52:09
Yii
EVOSandru6, 2015-08-18 14:52:09

Why doesn't yii define an additional safe attribute on a post request?

Good afternoon,
There is a Users model . In it, I included 2 properties not from the table

class Users extends CActiveRecord
{

public $test;
public $configsArray;
...
public function rules()
{
return
[
    [['test','configsArray'],'safe'],
...
]

...
}

A fragment of the form where I display these 2 properties:
...
echo $form->checkBoxList($model, 'configsArray', CHtml::listData(ConfigUser::model()->findAll(), 'id', 'name'));?>
...
echo $form->textField($model, 'test');?>
...

There is an action (CopnfigUsersController/update):
...
if(isset($_POST['Users']))
{
            $model->setAttributes($_POST['Users'],true);
            My::printArr($model->configsArray);
            My::printArr($model->test);
            My::printArr($model->attributes);
            die();
}

...

I get this picture:
Array
(
    [0] => 21
    [1] => 23
)

test)))))))))))))))

Array
(
    [id] => 7
    [name] => Михаил Боярский
    [role_id] => 1
    [email] => [email protected]
    [password] => 1b5e867a2e6bf3c45977b6a513b7af3e
    [contacts] => +77775556677
    [sys_date] => 
    [sys_date_update] => 
    [sys_user] => 
    [exist] => 1
    [status] => 1
    [category_id] => 1
    [photo_id] => 
    [photo] => 
)

Those. $model->configsArray and $model->test are not taken as part of the whole $model->attributes . Can this be fixed somehow?
And another question: after unsuccessful saving in this form:
var_dump($model->getErrors());
Issued:
array(0) { }
The log is empty(

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
C
corpsepk, 2015-08-18
@corpsepk

At least it should be public function rules()
and not public function relations ()
---
It's yii1
https://github.com/yiisoft/yii/blob/1.1.16/framewo...
Try changing to
array('test, configsArray' ,'safe'),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question