我的模型中有一个函数 如果我在view.php中使用 p>
我得到的值是3.但如果我再次这样做 p>
现在我得到1.任何想法,为什么我这样得到它。
这发生在estimate.php中的任何函数。
如果我第二次使用它,结果很奇怪。 p>
我在这里做错了吗? 我该如何解决这个问题?
谢谢。 p>
以下是 getDaysTotal code>,说是estimate.php。 p >
echo $ model-> DaysTotal;
code> pre>
echo $ model-> DaysTotal ;
code> pre>
getTotalDays code>函数的代码: p>
public function getDaysTotal(){
$ this-> discharge_date = strtotime($ this-> discharge_date);
$ this-> admission_date = strtotime($ this-> admission_date);
$ datediff = ($ this-> discharge_date - $ this-> admission_date);
$ fraction_days =($ datediff /(60 * 60 * 24));
if($ fraction_days< 1){\ n返回1;
} elseif(($ datediff)%(60 * 60 * 24)< 10800){
$ option2 = floor($ datediff /(60 * 60 * 24));
返回 $ option2;
} elseif(($ datediff%86400)> 10800&&($ datediff%86400)< 21600){
$ option3 = ceil($ datediff /(60 * 60 * 24)* 2)/ 2;
返回$ option3;
} elseif(($ datediff%86400)> 21600){
$ option4 = ceil($ datediff / 86400);
返回$ option4;
}
code> pre>
div>
Well I have a function getDaysTotal
in my model say estimate.php.
If in my view.php if I use
echo $model->DaysTotal;
I get the value 3. But if I do it again
echo $model->DaysTotal;
Now I get 1. Any idea, why I am getting it like this. This is happening for any function in estimate.php. If I am using it for second time the result is weird.
Am I doing anything wrong here? How can I correct this? Thanks.
Here is the code for getTotalDays
function:
public function getDaysTotal() {
$this->discharge_date = strtotime($this->discharge_date);
$this->admission_date = strtotime($this->admission_date);
$datediff = ($this->discharge_date - $this->admission_date);
$fraction_days = ($datediff/(60*60*24));
if ($fraction_days < 1){
return 1;
}elseif(($datediff)%(60*60*24) < 10800){
$option2 = floor($datediff/(60*60*24));
return $option2;
}elseif(($datediff%86400) > 10800 && ($datediff%86400)<21600) {
$option3 = ceil($datediff/(60*60*24)*2)/2;
return $option3;
}elseif (($datediff%86400) >21600){
$option4= ceil($datediff/86400);
return $option4;
}