比较yii2中的两个字段

时间:2015-11-03 09:26:23

标签: php yii yii2

如果它们相同,我想比较并返回错误消息。

尝试这样但不能正常工作

[['HRMS_candidateAlternateEmail'], '!compare', 'compareAttribute' => 'HRMS_candidateEmail'],

什么是写作方式。

2 个答案:

答案 0 :(得分:1)

!compare更改为compare

[['HRMS_candidateAlternateEmail'], 'compare', 'compareAttribute' => 'HRMS_candidateEmail', 'operator'=>'!='],

更多信息herehere。希望有所帮助。

答案 1 :(得分:0)

我发现它刚刚添加 [['HRMS_candidateAlternateEmail'], 'compare', 'compareAttribute' => 'HRMS_candidateEmail','operator'=>'!='], 并且有效。

    <!DOCTYPE html>
<html>
<head>
<style> 
html{ 
width:auto;                          /* Does auto will apply the background-color automatically to the display screen */
height:100%;                        /* 100% means 100% of the display browser??*/
margin-left:1%; margin-right:1%;   /*does changing the value of the margin will change anything in the page*/
margin-top:1%;margin-bottom:1%;
padding-left:1%;padding-right:1%;
padding-top:1%;Padding-bottom:0%;
border: 1px solid black;
background-color: red;
}
body{
background-color: #00FF00; 
width:50%;                   /* does it means 50% of the width stated above in the html (auto)*/
height:50%;              /*does it means 50% of the height of the display browser or we have to add the padding-top(1%) in html*/
position: fixed;
top: 25%;              /* does it mean that the body is shifted to below 25% of it's heigh or 25% of the display browser? */
left:25%;     /*  what is the different if i give 0% to left and i changed the margin-left value to 25%*/
border: 2px solid black ;
margin-top: 0px;
margin-left: 0px;}
header{width:50%;height:auto;
top: 25%;left:25%;  /* what does it mean here the value given to top and left??*/
border: 2px solid black ;
margin-top: 10%;
margin-left: 25%;}
h1{margin: 5px; color: blue;}
</style>
</head>
<body>
<header>
<h1> MY First webpage </h1>
</header>   
</body>
</html>