我正在创建产品报价,这就是我在控制器
中创建多个模型的原因public function actionCreate()
{
$model = new Offer();
$wmodel = new Wmoffer();
$pmodel = new Product();
$ummodel = new Unitofmeasurement();
$qvmodel = new OfferingValue();
$blmodel = new OfferLocation();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
// code manipulation
}else{
return $this->render('create', [
'model' => $model,
'wmodel' => $wmodel,
'pmodel' => $pmodel,
'qvmodel' => $qvmodel,
'blmodel' => $blmodel,
'ummodel' => $ummodel
]);
}
我的所有模型都扩展了ActiveRecord方面Wmoffer()
,此模型如下所示
use Yii;
use yii\base\Model;
use yii\web\UploadedFile;
use yii\helpers\FileHelper;
class Wmoffer extends Model
{
public $bIsProductOrService;
public $iCatalogueID;
public $imageProduct;
public $nHasCurrencyValue;
public $nHasCurrencyValueMRP;
public $BusinesslocationIds;
public function rules()
{
// validation rules
现在我需要为开始,结束日期比较实现内联验证器[开始日期应该大于结束日期]
答案 0 :(得分:0)
调用$model->errors
后,您应该检查$model->validate()
值,以查找验证错误。
您的日期验证方法可以是:
public function validateDates($attribute, $params) {
if ($this->hasErrors()) {
return;
}
if ($this->dateStart > $this->dateEnd)) {
$this->addError($attribute, 'Start date can not be greater than end date');
}
}
将其添加到后端模型中的rules()
。