steffomio
(St Brinkmann)
September 28, 2010, 8:48am
1
Hi,
I’ve the
class AuthItemChild extends CActiveRecord
{
public $parent;
public $child;
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'AuthItemChild';
}
public function rules()
{
return array(
array('parent', 'save'),
array('parent', 'required'),
array('child', 'save'),
array('child', 'required'),
);
}
}
do this:
$model = new AuthItemChild;
$model->attributes = array('child' => 'testValue1', 'parent' => 'testValue2');
if(!$model->validate())
{
...
}
and get this error:
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'parent' cannot be null
It seems as the Class can’t get the Attributes child and parent.
But if I test this, all seems to be OK:
$x = $model->parent; // $x = testValue2
$x = $model->child; // $x = testValue1
Can anybody say, what is going wrong?
steffomio
(St Brinkmann)
September 28, 2010, 11:16am
3
mdomba:
What does
array('parent', 'save'),
and
array('child', 'save'),
do?
Oh!
Without that it works, thanks!
Well, I thougt ‘save’ make a security check for possible include Javascript, forbidden html and so on.
This Option I’ve seen any where and I was sure
array('parent', 'save'),
is it.
Hmm…looks like I have to read more Docu.
steffomio
(St Brinkmann)
September 28, 2010, 11:27am
4
Yes, there exists an option ‘save’.
So leave blank save option is not the solution.
abstract class CValidator extends CComponent
{
/**
* @var array list of built-in validators (name=>class)
*/
public static $builtInValidators=array(
'required'=>'CRequiredValidator',
'filter'=>'CFilterValidator',
'match'=>'CRegularExpressionValidator',
'email'=>'CEmailValidator',
'url'=>'CUrlValidator',
'unique'=>'CUniqueValidator',
'compare'=>'CCompareValidator',
'length'=>'CStringValidator',
'in'=>'CRangeValidator',
'numerical'=>'CNumberValidator',
'captcha'=>'CCaptchaValidator',
'type'=>'CTypeValidator',
'file'=>'CFileValidator',
'default'=>'CDefaultValueValidator',
'exist'=>'CExistValidator',
'boolean'=>'CBooleanValidator',
'safe'=>'CSafeValidator',
'unsafe'=>'CUnsafeValidator',
);
zaccaria
(Matteo Falsitta)
September 28, 2010, 11:30am
5
Is saFe, not saVe.
CSafeValidator actually does not do any validation, it just make safe the attribute.
It is unuseful if you have already other validators.
100% right
steffomio
(St Brinkmann)
September 28, 2010, 2:56pm
6
Yeah! Right! sa[size="4"]f[/size] e, not sa[size="4"]v[/size] e.
Ok, safe validation is a child of all other validations.
Thanks!