2013-11-25 155 views
2

我想访问类CakeTime中我的模型和CakePHP似乎并不认识它。类::蛋糕时间模型蛋糕PHP

这里是我的代码:

<?php 
App::uses('AppModel', 'Model', 'CakeTime', 'Utility'); 

class Rex extends AppModel { 

public function month_entries($created){ 

    //création des mois qui vont servir de critère de recherche 
    $month=CakeTime::format("$created", '%Y-%m'); 

    //on récupère le 1er du mois recherché 
    $month=$month."-01"; 

    //on se place au premier du mois suivant 
    $month_plus_un=date('Y-m-d', strtotime("+1 month",strtotime($month))); 

    $count = $this->Article->find('count', array(
    'conditions' => array(
     'Rex.date_incident >='=> $month, 
      'Rex.date_incident <'=> $month_plus_un))); 

    return $count; 

} 

我,只要我打电话CakeTime得到一个错误。

我错过了什么语法?有关如何在Model中调用核心库实用程序的文档尚不清楚。

谢谢!

回答

3

App::uses(...)声明是错误的,它shoulld是: App::uses(string $class, string $package),所以,变化:

App::uses('AppModel', 'Model', 'CakeTime', 'Utility'); 

App::uses('AppModel', 'Model'); 
App::uses('CakeTime', 'Utility'); 
+0

,这就是为什么我爱互联网和计算器! btw:你知道我如何直接从模型中调用find('count')吗? – Malcoolm

+1

@Malcoolm,你可以做$ this-> find('count'....);直接 –

+0

完美!我正在尝试$ this-> Model-> find :) – Malcoolm