<?php
class LoggableBehavior extends CActiveRecordBehavior
{
private $_oldattributes = array();
public function afterSave($event)
{
$newattributes = $this->Owner->getAttributes();
$oldattributes = $this->getOldAttributes();
if (!$this->Owner->isNewRecord) {
// compare old and new
foreach ($newattributes as $name => $value) {
if (!empty($oldattributes)) {
$old = $oldattributes[$name];
} else {
$old = '';
}
if ($value != $old) {
$log=new LogTable();
$log->old_value = $old;
$log->new_value = $value;
$log->action = 'CHANGE';
$log->model = get_class($this->Owner);
$log->model_id = $this->Owner->getPrimaryKey();
// Conditions for primary key advanced for more one columns.
if(is_array($log->model_id))
$log->model_id = implode('#', $log->model_id);
$log->field = $name;
$log->stamp = date('Y-m-d H:i:s');
$log->user_id = $userid;
$log->save();
}
}
// ...
public function afterFind($event)
{
// Save old values
$this->setOldAttributes($this->Owner->getAttributes());
return parent::afterFind($event);
}
public function getOldAttributes()
{
return $this->_oldattributes;
}
public function setOldAttributes($value)
{
$this->_oldattributes=$value;
}
}
--
YFB - Yii Framework Brasil
04/2011: Anexos de até 250kb foram autorizados pelos membros da lista. Use com moderação.
---
You received this message because you are subscribed to the Google Groups "YFB - Yii Framework Brasil" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yii-framework-br...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/yii-framework-brasil/c20300ee-49e7-4e7a-860e-3f70aa292b8e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Fabio, o problema é como não fazer gambiarra no Behavior para recuperar esses dados.
--
YFB - Yii Framework Brasil
04/2011: Anexos de até 250kb foram autorizados pelos membros da lista. Use com moderação.
---
You received this message because you are subscribed to the Google Groups "YFB - Yii Framework Brasil" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yii-framework-br...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/yii-framework-brasil/77489b4a-e648-479a-8362-2a8b33032999%40googlegroups.com.
public function getFormatAttributes() {
$model = new DMConexao;
$model->attributes = $this->getAttributes();
$model->principal = ($model->principal == 'S') ? 'Sim' : 'Não';
$model->ativo = ($model->ativo == '1') ? 'Sim' : 'Não';
$model->data_alteracao = date('Y-m-d H:i:s', strtotime($model->data_alteracao));
$model->id_conexao = $this->id_conexao;
return $model->attributes;
}
getAttributes()
getFormatAttributes();
2013/12/27 Francis Rodrigues <tyler....@gmail.com>
To unsubscribe from this group and stop receiving emails from it, send an email to yii-framework-brasil+unsub...@googlegroups.com.