Re: Components vs Helpers vs Utilities

2013-01-25 Thread Michael Gaiser
I am having difficulty thinking of a time when I would need the same
function to be called in my model and my view. On my current project, I am
also needing to manipulate my dates as I have a non standard way of saving
them in the database. What I have done is manipulated them in the
controller using a Component so these functions can used in different
controllers. I get the data from the model, use the functions in
my component to manipulate the data and then pass that to the view, which
displays it as is.

Is that similar to what you are trying or am I misunderstanding your goals?

~Michael

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: Components vs Helpers vs Utilities

2013-01-25 Thread lowpass
On Fri, Jan 25, 2013 at 4:53 PM, tron tken...@gmail.com wrote:
 Im trying to wrap my head around utilzing some functionality at all levels
 of MVC. Right now, I'm writing a component that performs several date
 functions for my app (the date utility is insufficient for what Im doing).
 The problem is I need the these functions in both my models and views as
 well. I'd imagine writing my own Utility is the best option as it can be
 used anywhere but they seem off limits as they are only contained within
 the Lib. I also cant find any information on writing a Utility. Yes, I could
 just go write one and add it to Lib/Utilities but I'm looking for some
 feedback on this issue as I've faced it several times. If you need to share
 functionality between all layers of the MVC, is using utilities the only way
 to do it without having to load a component/helper/behavior on the fly?

If CakeTime doesn't have what you want you could extend it.

app/Lib/Utility/MyTime.php :

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

class MyTime extends CakeTime {

public function foo($bar = null) {

}
}

In your controller/Model/View :

App::uses('MyTime', 'Utility');

...

$foo = MyTime::foo($bar);

But if all you want/need is a plain function (ie. no class) you could
just put in bootstrap.php

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.