开发者

Code Igniter "created" and "modified"

开发者 https://www.devze.com 2023-02-14 04:50 出处:网络
I\'m new to CI but I know CakePHP pretty well. I\'ve searched the documentation of CI and haven\'t found this.

I'm new to CI but I know CakePHP pretty well. I've searched the documentation of CI and haven't found this.

In CakePHP the fields "created" and "modified" were automatically populated by the "save" function. Does CI have two fields like that? Or can he automatically populate something?

EDIT:

开发者_开发知识库

Ok.. I've extended the CI_Model class and now, is there a function such as beforeSave (from cake)? And shouldn't I rather extend the DB class (I use db->set and db->insert);


Is this ok?

<?php
class spj_Model extends CI_Model {
    var $table;

    function __construct() {
        parent::__construct();
    }

    function insert($data) {
        $this->load->helper('date');

        $data['created'] = date('Y-m-d H:i:s',now());
        $data['modified'] = date('Y-m-d H:i:s',now());

        return $this->db->insert($this->table,$data);
    }

    function update($data,$where=array()) {
        $this->load->helper('date');

        $data['modified'] = date('Y-m-d H:i:s',now());

        return $this->db->ubdate($this->table,$data, $where);
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号