Friday 15 April 2016

Yii, how to add current date or time or timestamp in DB field automatically

To add current date or time or timestamp in DB field automatically

Using Rules in model use it like below :



<?php

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    return array(
        array('title','length','max'=>255),
        array('title, created, modified', 'required'),
        array('modified','default',
              'value'=>new CDbExpression('NOW()'),
              'setOnEmpty'=>false,'on'=>'update'),
        array('created,modified','default',
              'value'=>new CDbExpression('NOW()'),
              'setOnEmpty'=>false,'on'=>'insert')
    );
}
?>



No comments:

Post a Comment

Setup VueJS in Laravel

Setup VueJS in Laravel 1. You will need to install javascript dependencies by running the following command on your terminal.      npm i...