I agree - but if you really want to utilise a model function, you can. To call a function within the same model, just use '$this->function()' - in other words, not '$this->Model->function()'.
I'd be tempted to adjust my data within the model rather than wait until I got to the view. This means the new calculated field is available wherever I call it in the future. Create your function. Then, after you have completed your find and have a data array ready to send back to the controller: $project['days_remaining'] = $this->getTiming($project['projected_end_date']); Obviously, I don't know what your data array looks like, so you'll need to adapt this. Another thing to consider (if you are using 1.3) is using virtual fields: http://book.cakephp.org/view/1608/Virtual-fields Jeremy Burns [email protected] On 7 May 2010, at 05:25, Dr. Loboto wrote: > Actually this task looks like pure view tasks. So better put code into > helper, not model. Except case when you need this timing data in > controller. > > On May 7, 4:40 am, bmcelhany <[email protected]> wrote: >> Hello, >> >> I have a model (Project) that has a projected_end_date field. What I'd >> like to do in the view is calculate the number of days from the >> current date until the projected end date and display how much time is >> left (or how many days overdue). This data really only needs to be in >> a single view, so I have no problems just embedding the logic directly >> into the view...I'm doing that now and it works fine. >> >> Even though it's working, it just feels wrong. It seems like this >> logic really should be in the model itself since it's data (calculated >> data and not stored in a table, but still data). >> >> Is this possible? I tried creating a getTiming() function in my >> Project model, but I couldn't figure out any way to call it from my >> view: >> >> echo $project['Project']->getTiming() >> echo $project->getTiming() >> echo $this->Project->getTiming() >> etc. >> >> I may end up just abstracting the logic out into a helper and calling >> that in the view. Any thoughts? Thanks! >> >> -Brian >> >> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others >> with their CakePHP related questions. >> >> You received this message because you are subscribed to the Google Groups >> "CakePHP" group. >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected] For more options, visit this group >> athttp://groups.google.com/group/cake-php?hl=en > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] For more options, visit this group at > http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
