Re: Defining custom constants in models
If it would have been a class constant, you could have accessed it with className::constant, e.g. class MyClass { const constant = 'constant value'; } however, you're defining a global constant in which the variable can be accessed anywhere during the execution of the script just by typing the constant name, e.g. define ('CONSTANT', value) On Aug 26, 4:44 am, pph7 wrote: > Thx! I didnt know about that yet! > > On Aug 26, 6:31 am, "Dr. Loboto" wrote: > > > If you're using PHP5 you can try class constants for > > this:http://ru2.php.net/manual/en/language.oop5.constants.php > > Because defines are _global_ as euromark mentioned. > > > On Aug 25, 5:53 pm, pph7 wrote: > > > > Hi there! > > > I am looking for a way to define custom constants in models. I realize > > > it is possible to define global constants in bootstrap.php and this > > > works well but for example, when I want to define user roles for > > > different acces rights like > > > > define("USER_ROLE_READER", 1); > > > define("USER_ROLE_PUBLISHER", 2); > > > > The logical way for me would to do that in the User model so I can > > > access these constant with > > > > User::USER_ROLE_READER > > > > etc. > > > > Is there a way to do this or do you disagree with my approach? > > > > thx! > > > mark --~--~-~--~~~---~--~~ 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: Defining custom constants in models
Thx! I didnt know about that yet! On Aug 26, 6:31 am, "Dr. Loboto" wrote: > If you're using PHP5 you can try class constants for > this:http://ru2.php.net/manual/en/language.oop5.constants.php > Because defines are _global_ as euromark mentioned. > > On Aug 25, 5:53 pm, pph7 wrote: > > > Hi there! > > I am looking for a way to define custom constants in models. I realize > > it is possible to define global constants in bootstrap.php and this > > works well but for example, when I want to define user roles for > > different acces rights like > > > define("USER_ROLE_READER", 1); > > define("USER_ROLE_PUBLISHER", 2); > > > The logical way for me would to do that in the User model so I can > > access these constant with > > > User::USER_ROLE_READER > > > etc. > > > Is there a way to do this or do you disagree with my approach? > > > thx! > > mark > > --~--~-~--~~~---~--~~ 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: Defining custom constants in models
If you're using PHP5 you can try class constants for this: http://ru2.php.net/manual/en/language.oop5.constants.php Because defines are _global_ as euromark mentioned. On Aug 25, 5:53 pm, pph7 wrote: > Hi there! > I am looking for a way to define custom constants in models. I realize > it is possible to define global constants in bootstrap.php and this > works well but for example, when I want to define user roles for > different acces rights like > > define("USER_ROLE_READER", 1); > define("USER_ROLE_PUBLISHER", 2); > > The logical way for me would to do that in the User model so I can > access these constant with > > User::USER_ROLE_READER > > etc. > > Is there a way to do this or do you disagree with my approach? > > thx! > mark --~--~-~--~~~---~--~~ 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: Defining custom constants in models
since when are constants NOT global? if you define them in your model (above the class statement) just refer to them like you usually would echo USER_ROLE_READER etc thats all there is to it On 25 Aug., 12:53, pph7 wrote: > Hi there! > I am looking for a way to define custom constants in models. I realize > it is possible to define global constants in bootstrap.php and this > works well but for example, when I want to define user roles for > different acces rights like > > define("USER_ROLE_READER", 1); > define("USER_ROLE_PUBLISHER", 2); > > The logical way for me would to do that in the User model so I can > access these constant with > > User::USER_ROLE_READER > > etc. > > Is there a way to do this or do you disagree with my approach? > > thx! > mark --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---