我使用yii2 basic,我试图添加一条规则,该规则会比较用户提供的日期,如果超过6天则会给出错误。
我将如何做到这一点?我现在使用datepicker输入日期,我使用的格式为:format' => ' d-mm-yyyy
Model.php
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "invoices".
*
* @property integer $id
* @property string $invoice_number
* @property string $invoice_loadamount
* @property string $invoice_date
* @property integer $archive_id
* @property string $DateProcessed
*
* @property Archive $archive
*/
class Invoices extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'invoices';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['invoice_number', 'invoice_loadamount', 'invoice_date'], 'required'],
[['archive_id', 'invoice_number', 'invoice_loadamount'], 'integer'],
[['DateProcessed'], 'safe'],
[['invoice_number', 'invoice_loadamount', 'invoice_date'], 'string', 'max' => 100],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'invoice_number' => 'Invoice Number',
'invoice_loadamount' => 'Invoice Loadamount',
'invoice_date' => 'Invoice Date',
'archive_id' => 'Archive ID',
'DateProcessed' => 'Date Processed'];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getArchive()
{
return $this->hasOne(Archive::className(), ['id' => 'archive_id']);
}
}