本文整理汇总了PHP中CActiveRecordBehavior::beforeValidate方法的典型用法代码示例。如果您正苦于以下问题:PHP CActiveRecordBehavior::beforeValidate方法的具体用法?PHP CActiveRecordBehavior::beforeValidate怎么用?PHP CActiveRecordBehavior::beforeValidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CActiveRecordBehavior
的用法示例。
在下文中一共展示了CActiveRecordBehavior::beforeValidate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeValidate
/**
* Actions to take before validating the owner.
* @param CModelEvent $event
*/
public function beforeValidate($event)
{
parent::beforeValidate($event);
if ($this->owner->hasAttribute($this->statusAttribute) && !isset($this->owner->{$this->statusAttribute})) {
$this->owner->{$this->statusAttribute} = $this->defaultStatus;
}
}
示例2: beforeValidate
/**
* @param CModelEvent $event
*/
public function beforeValidate($event)
{
if (method_exists($this->getOwner(), 'setDefaultAttributes')) {
$this->getOwner()->setDefaultAttributes();
}
// will the following will be called twice?
return parent::beforeValidate($event);
}
示例3: beforeValidate
public function beforeValidate($event)
{
parent::beforeValidate($event);
foreach ($this->fields as $field) {
if (!is_a($this->owner->{$field}, 'CUploadedFile')) {
$this->owner->{$field} = CUploadedFile::getInstance($this->owner->model(), $field);
}
}
return true;
}
示例4: beforeValidate
public function beforeValidate($event)
{
$owner = $this->getOwner();
//salt
if ($owner->getIsNewRecord() && $owner->hasAttribute('salt')) {
$owner->salt = Common::generateSalt();
}
if ($owner->getScenario() === Users::SCENARIO_CHANGE_PASSWORD) {
$owner->currentPassword = $owner->salt . md5($owner->currentPassword);
}
return parent::beforeValidate($event);
}
示例5: beforeValidate
public function beforeValidate($event)
{
if (isset(Yii::app()->user)) {
$availableColumns = array_keys($this->owner->tableSchema->columns);
if ($this->owner->isNewRecord && empty($this->owner->{$this->createdByColumn})) {
if (in_array($this->createdByColumn, $availableColumns)) {
$this->owner->{$this->createdByColumn} = Yii::app()->user->id;
}
}
if (empty($this->owner->{$this->updatedByColumn})) {
if (in_array($this->updatedByColumn, $availableColumns)) {
$this->owner->{$this->updatedByColumn} = Yii::app()->user->id;
}
}
}
return parent::beforeValidate($event);
}
示例6: beforeValidate
public function beforeValidate($event)
{
$setAttributes = array();
foreach ($this->attributes as $attribute => $format) {
if (!$this->owner->hasAttribute($attribute)) {
continue;
}
$value = $this->owner->getAttribute($attribute);
if (empty($value) && $this->autoFill === false) {
continue;
}
if (empty($value)) {
$value = time();
} else {
if (!is_numeric($value)) {
$value = strtotime($value);
}
}
$setAttributes[$attribute] = $value;
}
$this->owner->setAttributes($setAttributes);
return parent::beforeValidate($event);
}
示例7: beforeDelete
public function beforeDelete($event)
{
UserFollow::model()->deleteAllByAttributes(array('object_model' => get_class($this->getOwner()), 'object_id' => $this->getOwner()->getPrimaryKey()));
return parent::beforeValidate($event);
}
示例8: beforeValidate
/**
* Invoked before the model is validated.
* Validates the password first
* @param CModelEvent $event the raised event
*/
public function beforeValidate($event)
{
$password = $event->sender->{$this->passwordAttribute};
$strategy = $this->getStrategy();
if ($strategy !== false && $password != $this->_hashedPassword && $password != "") {
$strategy->attributes = array($this->passwordAttribute);
$strategy->validate($event->sender);
}
return parent::beforeValidate($event);
}
示例9: beforeValidate
/**
* @param CModelEvent $event
*/
public function beforeValidate($event)
{
$this->getOwner()->setDefaultAttributes();
return parent::beforeValidate($event);
}