Re: Global Variable
but yes, miles is right - in this case you could simply put in your bootstrap.php On 10 Feb., 11:24, euromark wrote: > usually there are "bound" to a specific model (as an enum > etc):http://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-at... > > On 10 Feb., 02:13, "Krissy Masters" > 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 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Global Variable
usually there are "bound" to a specific model (as an enum etc): http://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-attributes/ On 10 Feb., 02:13, "Krissy Masters" 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 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
RE: Global Variable
Thanks you very much. That’s exactly what I was looking for. Will test out and also read the link article. Thanks! -Original Message- From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of ShadowCross Sent: Wednesday, February 09, 2011 11:20 PM To: CakePHP Subject: Re: Global Variable 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-CakePHP for additional details and configurations). On Feb 9, 5:54 pm, "Krissy Masters" 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: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf > Of Angel Robert Marquez > Sent: Wednesday, February 09, 2011 9:51 PM > To: cake-php@googlegroups.com > 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 > 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.organd help > others with their CakePHP related questions. > > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com 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.organd help > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Global Variable
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 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" > 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: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf > > Of Angel Robert Marquez > > Sent: Wednesday, February 09, 2011 9:51 PM > > To: cake-php@googlegroups.com > > 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 > > 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 > > cake-php+unsubscr...@googlegroups.com 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 > > cake-php+unsubscr...@googlegroups.com 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Global Variable
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-CakePHP for additional details and configurations). On Feb 9, 5:54 pm, "Krissy Masters" 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: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf > Of Angel Robert Marquez > Sent: Wednesday, February 09, 2011 9:51 PM > To: cake-php@googlegroups.com > 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 > 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.organd help > others with their CakePHP related questions. > > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com 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.organd help > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Global Variable
well, the model class would only be in one place and the objects that inherit those methods would be able to access the $timestamp variable created upon insertion and use it as a reference point that would allow you to reuse/polymorph one function based on the argument passed to it... no=yes unless, you want to over complicate things for no apparent good reason. On Wed, Feb 9, 2011 at 5:54 PM, Krissy Masters 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: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On > Behalf > Of Angel Robert Marquez > Sent: Wednesday, February 09, 2011 9:51 PM > To: cake-php@googlegroups.com > 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 > > 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 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+unsubscr...@googlegroups.com For more options, visit this group > at > http://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 > cake-php+unsubscr...@googlegroups.com For more options, visit this group > at > http://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 > cake-php+unsubscr...@googlegroups.com For more options, visit this group > at http://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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
RE: Global Variable
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: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of Angel Robert Marquez Sent: Wednesday, February 09, 2011 9:51 PM To: cake-php@googlegroups.com 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 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 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+unsubscr...@googlegroups.com For more options, visit this group at http://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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
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 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 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+unsubscr...@googlegroups.com For more options, visit this group > at http://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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Global Variable
Hi Rick, Thanks for reply I have done it this way Declaring Global Variable: Configure::write('var_name','var_value'); Reading Global Variable:Configure::read('var_name'); Regards Anand On Jun 19, 5:54 pm, Rick wrote: > You can write a new config value or you can define a variable or > constant in bootstrap.php. > > Rick > > On Jun 19, 8:42 am, Anand wrote: > > > Hello All, > > > How to define a global variable in CakePHP which i can use anywhere in > > the application. > > > Please provide a code sample. > > > Waiting for reply > > > Anand --~--~-~--~~~---~--~~ 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 For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Global Variable
You can write a new config value or you can define a variable or constant in bootstrap.php. Rick On Jun 19, 8:42 am, Anand wrote: > Hello All, > > How to define a global variable in CakePHP which i can use anywhere in > the application. > > Please provide a code sample. > > Waiting for reply > > Anand --~--~-~--~~~---~--~~ 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 For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: global variable confsion
Thanks AD7six, I think i was getting side tracked trying to reuse as much code as possible - when it is probably less efficent to do so. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: global variable confsion
What do you want to achieve? $currentDir[2] == first parameter for your method if I am guessing correctly. Why create a global array for something that is accessible (in a much easier form) anyway? Reffering to $currentDir would break if you accessed your method via a route with a different number of 'folders', or moved your application to a subfolder. That code looks like ListingsController extends AppController { function index ($type=null) { $today = ...; $nW = ...; $conditions = array('Ltype.Date>=$today",'Listing.Date'=>"<$nW"); if ($type){ $conditions['Ltype.Name']=>$type; } $fields = array('Ltype.name', 'Listing.name', 'Listing.date','Venue.name'); ... } } If you want to access the equivalent of $currentDir[2] in your beforeFilter, or somewhere else generic, you could use $this->params['pass'][0] to refer to the parameter. >Is it worth making $currentDir a global array? I would say no. HTH, AD7six PS. Code not tested, but should be about right. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: global variable confsion
That's quite usefull, but i suppose my problem goes a bit further. $currentDir = (explode("/", $_SERVER["REQUEST_URI"])); would change to: $currentDir = (explode("/", $this->here)); it's the way i use it to make different queries depending on the section: if ($currentDir[2] == ''){ $conditions = "(listing.date >= '$today') AND (listing.date < '$nW')"; $fields = array('Ltype.name', 'Listing.name', 'Listing.date', 'Venue.name'); }else{ $ltypeName = substr($currentDir[2], 0, -1); $conditions = "(ltype.name = $ltypeName) AND (listing.date >= '$today') AND (listing.date < '$nW')"; $fields = array('Ltype.name', 'Listing.name', 'Listing.date', 'Venue.name'); } Is it worth making $currentDir a global array? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: global variable confsion
why not use $this->here? Cheers, AD7six --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---