-3

I work with CakePHP 2.0. I made a new function sort and had no problem, if I take the table fields. But if I want to calculate something and give the result (method: 'Participant.year'=>'calculateyear' ) in my sort method, I have no result on my view.

function sort() { 
    $participants = $this->Participant->find('all', array(
    'conditions'=>array('Participant.sex'=>'m','Participant.year'=>'calculateyear'),
    'order'=>array('Participant.communitieRank'=>'ASC','Communitie.name'=>'ASC')
    ));
    $this->set('participants', $participants);  
  }

  function calculateyear ($jahr) {
      $jahr = '2000'; 
      return $jahr;
 }

2 Answers2

1

assuming you are in your PartecipantsController I guess what you want to do is:

function sort() { 
    $participants = $this->Participant->find('all', array(
    'conditions'=>array(
        'Participant.sex'=>'m',
        'Participant.year'=> $this->calculateyear(2000)
    ),
        'order'=>array('Participant.communitieRank'=>'ASC','Communitie.name'=>'ASC')
    ));
    $this->set('participants', $participants);  
  }

but your question is not clear at all

arilia
  • 9,373
  • 2
  • 20
  • 44
0

thats my solution, it works :)

function calculateyear ($year) {
     $today = date("Y");
     $year = $today - $year;
      return  $year;
  }  

  function kat1w() { 
    $participants = $this->Participant->find('all', array(
        'conditions'=>array('Participant.sex'=>'f',
       'Participant.year >='=>$this->calculateyear(9)),
       'order'=>array('Participant.communitieRank'=>'ASC','Communitie.name'=>'ASC')
    ));
    $this->set('participants', $participants,$this->Paginator->paginate());  
  }