Wednesday, March 21, 2012

Accessing function from view

Hi,
Abstract: I would like to perform a calculus from $start_date and
$end_date fetched from the MySQL table. Where should I put my calculus
function ?

Detail: I am new to CakePhp. I have this Controller:

class PostersController extends AppController {
var $name = 'Posters';

function index (){
$request = $this->Poster->find('all');
$this->set('posters', $request);
}

In my Posters MySQL table, I have $start_date and $end_date fields.
I want to have a function to perform a calculus for the duration using
this function.

function PosterDuration ($start_date, $end_date){
$duration = $start_date->diff($end_date);
return $duration;
}

I want to view the $duration in my View for each Poster. However I
don't know where to put this function logic.

1- I thought to put it as a private function in my PostersController,
however I don't know if I could access it from the Posters.ctp View.
2- I thought of creating a Component called
DuractionCalculusComponent.
3- Could it be a behaviour ?

Since I am new in CakePhp, I have modest knowledge and don't know
which option to chose. Your help will be appreciated.

Thank You

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate