Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从模型cakephp中检索数据_Cakephp_Date_Model - Fatal编程技术网

如何从模型cakephp中检索数据

如何从模型cakephp中检索数据,cakephp,date,model,Cakephp,Date,Model,我有一个名为updateos()的控制器函数,该函数的模型Outofserviceday和一个名为outofservicedays的表。该表有3个字段-id、userid、outofservicedays 我想从今天到本月最后一天停止服务 如何在带有两个参数的Outofserviceday模型中编写函数today和Monthedday类似 function ($today $monthedDday) { } 在我的控制器中,我得到两个日期 $today = date("Ymd"); $mont

我有一个名为
updateos()
的控制器函数,该函数的模型
Outofserviceday
和一个名为
outofservicedays
的表。该表有3个字段-
id
userid
outofservicedays

我想从今天到本月最后一天停止服务 如何在带有两个参数的
Outofserviceday
模型中编写函数
today
Monthedday
类似

function ($today $monthedDday) { }
在我的控制器中,我得到两个日期

$today = date("Ymd");
$monthend=date("ymd", strtotime($today));

我编辑了我所有的错误

只需将时间转换为unix时间戳,并对照目标日期检查值即可

例如:

$no_service_days = $this-> Outofserviceday->find('all');

$nsd_array = array();

$end_date = strtotime($monthend); // or strtotime('31-01-12');

foreach ($no_service_days as $key => $day) : 
   $record_u_time = strtotime($day['Outofserviceday']['outofservicedays']);
   if($record_u_time < $end_date){
      $nsd_array[] = $day;
   }
endforeach;

pr($nsd_array);
$no\u service\u days=$this->outofservice day->find('all');
$nsd_数组=数组();
$end_date=strottime($monthend);//或标准时间('31-01-12');
foreach($key=>$day的无服务天数):
$record____时间=strotime($day['Outofserviceday']['outofservicedays']);
如果($记录时间<$结束日期){
$nsd_阵列[]=$day;
}
endforeach;
pr($nsd_阵列);
这是一个松散的方法,你应该使用的技术,因为你的代码和命名约定是诚实的相当混乱


我在您的表中没有看到
date
字段,因此我假设它是
outofservicedays
和您的
$monthend=date(“ymd”,strotime($today))
似乎不是将来或过去的日期。

重新编辑您的帖子,您的代码不起作用,没有分隔符,函数名……您违反所有CakePHP约定规则的具体原因是什么?模型名、表名和字段名都是“关闭”的。实际上这不是正确的名称,我只是添加了一个示例如果有人知道如何从模型中访问特定数据,请告诉我