动态数据及设施

来源:互联网 发布:长沙网络推广wyztg 编辑:程序博客网 时间:2024/06/10 05:38
记录以来夹具的声明为一个类属性,不能轻易使用功能或其他定义设备的动态数据。为了解决这个问题,您可以定义记录美元固定的init()函数。例如,如果你想要所有的创建和更新时间戳来反映今天的日期你可以做以下几点:
class ArticleFixture extends CakeTestFixture {    public $fields = array(        'id' => array('type' => 'integer', 'key' => 'primary'),        'title' => array('type' => 'string', 'length' => 255, 'null' => false),        'body' => 'text',        'published' => array('type' => 'integer', 'default' => '0', 'null' => false),        'created' => 'datetime',        'updated' => 'datetime'    );    public function init() {        $this->records = array(            array(                'id' => 1,                'title' => 'First Article',                'body' => 'First Article Body',                'published' => '1',                'created' => date('Y-m-d H:i:s'),                'updated' => date('Y-m-d H:i:s'),            ),        );        parent::init();    }}
当覆盖init()只记得总是调用父::init()。
0 0
原创粉丝点击