1

我正在用一个非常简单的课程来做这件事,只是为了学习,但我无法让它像我在http://agiletoolkit.org/learn/understand/model/actions中看到的那样工作

这是类定义:

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();
    }  
}

我也尝试了 samble 页面格式:

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;
    }
}

任务测试页面也很简单:

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();
        });  
    }
}

在模型描述的两个实现中,都保存在表单中插入的值,而不是“测试”。如果我在 beforeTest 函数中回显 $this->description 或 $m->description 在我设置它之前它是空的,然后是“测试”,但它不会对生成的 sql 产生任何影响。当然我错过了一些东西,但是¿什么?

谢谢!!

4

1 回答 1

1

改变值的正确方法是:

$this['description'] = 'test;
于 2012-06-17T08:06:45.647 回答