Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class ::CakeTime in Model cakePHP

Tags:

cakephp

i'm trying to access the class CakeTime in my Model and CakePHP doesn't seem to recognize it.

Here's my code:

<?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;

}

I get an error as soon as i call CakeTime.

am i missing something in syntax ? The documentation is unclear on how to call core library utilities in Model.

Thanks!

like image 760
Malcoolm Avatar asked Nov 24 '25 15:11

Malcoolm


1 Answers

your App::uses(...) declaration is wrong, it shoulld be: App::uses(string $class, string $package) , so, change:

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

to

App::uses('AppModel', 'Model');
App::uses('CakeTime', 'Utility');
like image 163
Sudhir Bastakoti Avatar answered Nov 26 '25 10:11

Sudhir Bastakoti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!