You can use constants or the Configure class. Place the code within
your bootstrap file and it should be available everywhere.

On Feb 9, 6:50 pm, ShadowCross <[email protected]> wrote:
> You can try adding it to your app_model:
>
> config/core.php:
>
> Configure::write('BRAND_NEW', '-24 hours');
> Configure::write('NEW', '-48 hours');
> Configure::write('RECENTLY_NEW', '-96 hours');
>
> app_model.php:
> function rowNewness($data = null) {
>     if (!$data) {
>         $data = $this->data;
>     }
>     foreach ( array( 'BRAND_NEW', 'NEW', 'RECENTLY_NEW' ) as
> $newness ) {
>         if ( $data[$model->alias]['created'] < date('Y-m-d H:i:s',
> strtotime(Configure::read($newness))) ( {
>             return $newness;
>         }
>     }
>     return 'NOT_NEW';
>
> }
>
> somethings_controller.php:
> ...
>     switch ( $this->Something->rowNewness() ) {
>         case 'BRAND_NEW':
>             // fun stuff for brand new records
>             break;
>         case 'NEW':
>             // other fun stuff for new records
>             break;
>         case 'RECENTLY_NEW':
>             // still other fun stuff for recently new records
>     }
>
> This should work if you are only testing the newness of records at the
> Model and Controller level, but not at the View level.  If you want to
> be able to test at the View level as well, you can try creating a
> global function in config/bootstrap.php 
> (see:http://book.cakephp.org/view/954/Bootstrapping-CakePHPfor additional
> details and configurations).
>
> On Feb 9, 5:54 pm, "Krissy Masters" <[email protected]>
> wrote:
>
> > No, if that’s in 15 places then that’s of no use to me changing it in 15
> > places
>
> > New USERS, POSTS, EVENTS various models / controller
>
> > All have created dates, now I want a standard set of “time” definitions to
> > define if each of these is new, brand_new, recently_new…so if I say 2 months
> > from now NEW is now less than 12 hours I don’t have to go everywhere looking
> > for if this $created less than 24 hours and make it 12, I just want to
> > change it in 1 spot. $created less than NEW / BRAND_NEW / RECENTLY_NEW...so
> > on so on.....
>
> > From: [email protected] [mailto:[email protected]] On Behalf
> > Of Angel Robert Marquez
> > Sent: Wednesday, February 09, 2011 9:51 PM
> > To: [email protected]
> > Subject: Re: Global Variable
>
> > interface when{
> > public function new();
>
> > }
>
> > class shtuff implements when {
> > function new($type);
> > if ($type="helluv"){...blah1}
> > ifelse($type="retro"){..blah2}
>
> > }
>
> > $now = new shtuff;
> > $now->new('recent');
> > On Wed, Feb 9, 2011 at 5:13 PM, Krissy Masters <[email protected]>
> > wrote:
> > Quick question.
>
> > I have 3 types / classifications of "NEW"
>
> > Brand new = less than 24 hours
> > New more than 24 but less than 48 hours
> > And recently new more than 48 but less than 96 hours
>
> > Now how can I define these globally so if I have in the code anywhere > NEW
> > or < RECENT rather than tracing back all the spots where -24 hours so I can
> > simply change the NEW, BRAND_NEW and RECENTLY_NEW if I want to increase or
> > decrease their values later on
>
> > So I can use something like this in the code:
> > if ( $created < BRAND_NEW ){
> > //fun stuff here
>
> > }
>
> > So I can change them in 1 spot and reflect on the site throughout.
>
> > Configure::write('BRAND_NEW', date( 'Y-m-d H:i:s', strtotime( "-24 hours" )
> > ) );
>
> > Thanks
>
> > --
> > Our newest site for the community: CakePHP Video 
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > [email protected] For more options, visit this group 
> > athttp://groups.google.com/group/cake-php
>
> > --
> > Our newest site for the community: CakePHP Video 
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp
> > others with their CakePHP related questions.
> >  
> >  
> > To unsubscribe from this group, send email to
> > [email protected] For more options, visit this group 
> > athttp://groups.google.com/group/cake-php

-- 
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
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to