I'm doing this with a very simple class, just to learn, but I'm not able to have it working like I see in http://agiletoolkit.org/learn/understand/model/actions
This is the class definition:
class Model_Task extends Model_Table {
public $table='task';
function init(){
parent::init();
$this->addField('user_id')->system(true);
$this->addField('name')->mandatory('No has indicado un nombre para la tarea');
$this->addField('description')->dataType('text');
$this->addField('state')->system(true);
$this->addHook('beforeSave',function($m){
$m->description='test';
return $m;
});
$this->debug();
}
}
I tried whih the samble page format too:
class Model_Task extends Model_Table {
public $table='task';
function init(){
parent::init();
$this->addField('user_id')->system(true);
$this->addField('name')->mandatory('No has indicado un nombre para la tarea');
$this->addField('description')->dataType('text');
$this->addField('state')->system(true);
$this->addHook('beforeSave',$this);
$this->debug();
}
function BeforeSave(){
$this->description='test';
return $this;
}
}
The task test page is simple too:
class page_Task extends Page {
function init(){
parent::init();
$m=$this->add('Model_Task');
$f=$this->add('Form');
$f->setModel($m);
$f->addSubmit('Guardar');
//Task submit
$f->onSubmit(function($form){
$form->update();
$form->js()->univ()->redirect('index?add_ok=1')->execute();
});
}
}
On both implementqtions of model description is saved with the value inserted in the form, not with 'Test'. If I echo $this->description or $m->description inside beforeTest function it's empty before I set it and 'Test' after, but it dos not make nothing whith the generated sql. Sure I'missing somethig, but ¿WHAT?
Thanks!!