Re: Using Configure or other methods to set app-wide "constants"
Euromark, Good point. This is an intranet app protected by a SSO sign-on that sets REMOTE_USER. I am trying to set 3 global variables at the outset such as REMOTE_USER that will be visible to all other components. This will include a user-specific identifier that will require a table lookup. So the scope/applicability will be "one user" but I am not sure about the issue of persistence. By adding some of this to bootstrap.php, my understanding is that it will be run for any executed view calling a controller+model. If I could set that identifier in a session variable, I guess that would avoid subsequent table lookups to get that identifier. Maybe I need to get more comfortable with session variables, but this is an application with a limited set of users and very low load, so I might just tolerate some lookup overhead for the time being to set that identifier. Thanks for your reply and patience. J On Jan 3, 7:46 am, euromark wrote: > you didnt specify if you want them available app-wide for this request > ONLY or more persistent > without knowing that it is pure speculation (as bujanga did) what best > to use. > > non-persistent: > - constants (one user) > - Configure (one user) > > persistent > - (cache) files (all user) > - db (all user) > - session (one user) > - cookies (one user) > > a huge variety as you can see > all have a purpose that fits best > > On 3 Jan., 15:10, Thiago Belem wrote: > > > > > About the: > > > var $ipaddr=$_SERVER['REMOTE_ADDR']; > > > I don't think this is possible since class attributes must receive literal > > values, you can't pass a variable on the class definition, only inside a > > method or constructor. > > > -- > > ***Thiago Belem* > > Desenvolvedor > > Rio de Janeiro - RJ - Brasil > > > +55 (21) 8865.9250 > > thiagobelem.net > > cont...@thiagobelem.net > > > *Skype / gTalk **»* thiago.belem.web > > *LinkedIn* *»* br.linkedin.com/in/thiagobelem/pt* > > Assando Sites*, curso de CakePHP *»* assando-sites.com.br > > > 2012/1/3 Kanwal > > > > You can use a simple way in app_controller like > > > var $ipaddr=$_SERVER['REMOTE_ADDR']; > > > > and access in any controller function like: > > > echo $this->ipaddr; > > > > On Jan 2, 7:12 pm, geste wrote: > > > > Gary, euromark, > > > > > OK, yes I was able use Configure::write in boostrap.php. > > > > > If I can just use the CakePHP database connector, I think I'll just > > > > write a small snippet that looks up that secondary identifier and add > > > > that to bootstrap.php. > > > > > Thanks, > > > > > J > > > > > On Jan 2, 2:35 pm, bujanga wrote: > > > > > > This is really not a configuration item, though you can set it using > > > > > Configure::write(). Of course, $_SERVER['REMOTE_ADDR'] must be > > > > > provided by your web server. > > >http://php.net/manual/en/reserved.variables.server.php > > > > > If you are trying to create a user setting, a session cookie would be > > > > > much more appropriate. Alternatively, I often log the user's IP > > > > > address to the DB upon login. > > > > > > Gary > > > > > > On Mon, Jan 2, 2012 at 3:48 PM, geste wrote: > > > > > > All, > > > > > > > I am looking for the easiest, most global way to set a couple of > > > > > > app- > > > > > > wide constants, more or less, that would derive from Apache > > > variables, > > > > > > specifically $_SERVER['REMOTE_USER'] and $_SERVER['REMOTE_ADDR'] and > > > > > > that would be used throughout the app both in models and > > > > > > controllers. > > > > > > > A Configure:write method in app_controller.php seemed like it might > > > be > > > > > > the place to set like so: > > > > > > > Configure::write('User.Address',$_SERVER['REMOTE_ADDR']); > > > > > > > but it looks like that method only wants text strings for the write > > > > > > method and anyhow it did not work whether I tried it at top of > > > > > > app_controller.php or in a beforeFilter function in > > > > > > app_controller.php. > > > > > > > I also tried more generic means such as using PHP getenv like so: > > > > > > > $ipaddr = getenv('REMOTE_ADDR'); > > > > > > > and that partly works, but I am not seeing a way to make it glovally > > > > > > available. Using the form > > > > > > > var $ipaddr = getenv('REMOTE_ADDR'); > > > > > > > at top of app_controller.php just does not work, but I am guessing I > > > > > > am misusing that "var" construct. > > > > > > > Any thoughts welcome! > > > > > > > J > > > > > > > -- > > > > > > Our newest site for the community: CakePHP Video Tutorialshttp:// > > > tv.cakephp.org > > > > > > Check out the new CakePHP Questions > > > sitehttp://ask.cakephp.organdhelpotherswith 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
Re: Using Configure or other methods to set app-wide "constants"
Thiago, Thanks. Yes that approach was what I tried first but trying to declare that in app_controller.php actually led to a white screen. Jim On Jan 3, 6:10 am, Thiago Belem wrote: > About the: > > var $ipaddr=$_SERVER['REMOTE_ADDR']; > > I don't think this is possible since class attributes must receive literal > values, you can't pass a variable on the class definition, only inside a > method or constructor. > > -- > ***Thiago Belem* > Desenvolvedor > Rio de Janeiro - RJ - Brasil > > +55 (21) 8865.9250 > thiagobelem.net > cont...@thiagobelem.net > > *Skype / gTalk **»* thiago.belem.web > *LinkedIn* *»* br.linkedin.com/in/thiagobelem/pt* > Assando Sites*, curso de CakePHP *»* assando-sites.com.br > > 2012/1/3 Kanwal > > > > > You can use a simple way in app_controller like > > var $ipaddr=$_SERVER['REMOTE_ADDR']; > > > and access in any controller function like: > > echo $this->ipaddr; > > > On Jan 2, 7:12 pm, geste wrote: > > > Gary, euromark, > > > > OK, yes I was able use Configure::write in boostrap.php. > > > > If I can just use the CakePHP database connector, I think I'll just > > > write a small snippet that looks up that secondary identifier and add > > > that to bootstrap.php. > > > > Thanks, > > > > J > > > > On Jan 2, 2:35 pm, bujanga wrote: > > > > > This is really not a configuration item, though you can set it using > > > > Configure::write(). Of course, $_SERVER['REMOTE_ADDR'] must be > > > > provided by your web server. > >http://php.net/manual/en/reserved.variables.server.php > > > > If you are trying to create a user setting, a session cookie would be > > > > much more appropriate. Alternatively, I often log the user's IP > > > > address to the DB upon login. > > > > > Gary > > > > > On Mon, Jan 2, 2012 at 3:48 PM, geste wrote: > > > > > All, > > > > > > I am looking for the easiest, most global way to set a couple of app- > > > > > wide constants, more or less, that would derive from Apache > > variables, > > > > > specifically $_SERVER['REMOTE_USER'] and $_SERVER['REMOTE_ADDR'] and > > > > > that would be used throughout the app both in models and controllers. > > > > > > A Configure:write method in app_controller.php seemed like it might > > be > > > > > the place to set like so: > > > > > > Configure::write('User.Address',$_SERVER['REMOTE_ADDR']); > > > > > > but it looks like that method only wants text strings for the write > > > > > method and anyhow it did not work whether I tried it at top of > > > > > app_controller.php or in a beforeFilter function in > > > > > app_controller.php. > > > > > > I also tried more generic means such as using PHP getenv like so: > > > > > > $ipaddr = getenv('REMOTE_ADDR'); > > > > > > and that partly works, but I am not seeing a way to make it glovally > > > > > available. Using the form > > > > > > var $ipaddr = getenv('REMOTE_ADDR'); > > > > > > at top of app_controller.php just does not work, but I am guessing I > > > > > am misusing that "var" construct. > > > > > > Any thoughts welcome! > > > > > > J > > > > > > -- > > > > > Our newest site for the community: CakePHP Video Tutorialshttp:// > > tv.cakephp.org > > > > > Check out the new CakePHP Questions > > sitehttp://ask.cakephp.organdhelpothers 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 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: Using Configure or other methods to set app-wide "constants"
you didnt specify if you want them available app-wide for this request ONLY or more persistent without knowing that it is pure speculation (as bujanga did) what best to use. non-persistent: - constants (one user) - Configure (one user) persistent - (cache) files (all user) - db (all user) - session (one user) - cookies (one user) a huge variety as you can see all have a purpose that fits best On 3 Jan., 15:10, Thiago Belem wrote: > About the: > > var $ipaddr=$_SERVER['REMOTE_ADDR']; > > I don't think this is possible since class attributes must receive literal > values, you can't pass a variable on the class definition, only inside a > method or constructor. > > -- > ***Thiago Belem* > Desenvolvedor > Rio de Janeiro - RJ - Brasil > > +55 (21) 8865.9250 > thiagobelem.net > cont...@thiagobelem.net > > *Skype / gTalk **»* thiago.belem.web > *LinkedIn* *»* br.linkedin.com/in/thiagobelem/pt* > Assando Sites*, curso de CakePHP *»* assando-sites.com.br > > 2012/1/3 Kanwal > > > > > > > > > You can use a simple way in app_controller like > > var $ipaddr=$_SERVER['REMOTE_ADDR']; > > > and access in any controller function like: > > echo $this->ipaddr; > > > On Jan 2, 7:12 pm, geste wrote: > > > Gary, euromark, > > > > OK, yes I was able use Configure::write in boostrap.php. > > > > If I can just use the CakePHP database connector, I think I'll just > > > write a small snippet that looks up that secondary identifier and add > > > that to bootstrap.php. > > > > Thanks, > > > > J > > > > On Jan 2, 2:35 pm, bujanga wrote: > > > > > This is really not a configuration item, though you can set it using > > > > Configure::write(). Of course, $_SERVER['REMOTE_ADDR'] must be > > > > provided by your web server. > >http://php.net/manual/en/reserved.variables.server.php > > > > If you are trying to create a user setting, a session cookie would be > > > > much more appropriate. Alternatively, I often log the user's IP > > > > address to the DB upon login. > > > > > Gary > > > > > On Mon, Jan 2, 2012 at 3:48 PM, geste wrote: > > > > > All, > > > > > > I am looking for the easiest, most global way to set a couple of app- > > > > > wide constants, more or less, that would derive from Apache > > variables, > > > > > specifically $_SERVER['REMOTE_USER'] and $_SERVER['REMOTE_ADDR'] and > > > > > that would be used throughout the app both in models and controllers. > > > > > > A Configure:write method in app_controller.php seemed like it might > > be > > > > > the place to set like so: > > > > > > Configure::write('User.Address',$_SERVER['REMOTE_ADDR']); > > > > > > but it looks like that method only wants text strings for the write > > > > > method and anyhow it did not work whether I tried it at top of > > > > > app_controller.php or in a beforeFilter function in > > > > > app_controller.php. > > > > > > I also tried more generic means such as using PHP getenv like so: > > > > > > $ipaddr = getenv('REMOTE_ADDR'); > > > > > > and that partly works, but I am not seeing a way to make it glovally > > > > > available. Using the form > > > > > > var $ipaddr = getenv('REMOTE_ADDR'); > > > > > > at top of app_controller.php just does not work, but I am guessing I > > > > > am misusing that "var" construct. > > > > > > Any thoughts welcome! > > > > > > J > > > > > > -- > > > > > Our newest site for the community: CakePHP Video Tutorialshttp:// > > tv.cakephp.org > > > > > Check out the new CakePHP Questions > > sitehttp://ask.cakephp.organdhelpothers 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 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: Using Configure or other methods to set app-wide "constants"
About the: var $ipaddr=$_SERVER['REMOTE_ADDR']; I don't think this is possible since class attributes must receive literal values, you can't pass a variable on the class definition, only inside a method or constructor. -- ***Thiago Belem* Desenvolvedor Rio de Janeiro - RJ - Brasil +55 (21) 8865.9250 thiagobelem.net cont...@thiagobelem.net *Skype / gTalk **»* thiago.belem.web *LinkedIn* *»* br.linkedin.com/in/thiagobelem/pt* Assando Sites*, curso de CakePHP *»* assando-sites.com.br 2012/1/3 Kanwal > You can use a simple way in app_controller like > var $ipaddr=$_SERVER['REMOTE_ADDR']; > > and access in any controller function like: > echo $this->ipaddr; > > > On Jan 2, 7:12 pm, geste wrote: > > Gary, euromark, > > > > OK, yes I was able use Configure::write in boostrap.php. > > > > If I can just use the CakePHP database connector, I think I'll just > > write a small snippet that looks up that secondary identifier and add > > that to bootstrap.php. > > > > Thanks, > > > > J > > > > On Jan 2, 2:35 pm, bujanga wrote: > > > > > > > > > > > > > > > > > This is really not a configuration item, though you can set it using > > > Configure::write(). Of course, $_SERVER['REMOTE_ADDR'] must be > > > provided by your web server. > http://php.net/manual/en/reserved.variables.server.php > > > If you are trying to create a user setting, a session cookie would be > > > much more appropriate. Alternatively, I often log the user's IP > > > address to the DB upon login. > > > > > Gary > > > > > On Mon, Jan 2, 2012 at 3:48 PM, geste wrote: > > > > All, > > > > > > I am looking for the easiest, most global way to set a couple of app- > > > > wide constants, more or less, that would derive from Apache > variables, > > > > specifically $_SERVER['REMOTE_USER'] and $_SERVER['REMOTE_ADDR'] and > > > > that would be used throughout the app both in models and controllers. > > > > > > A Configure:write method in app_controller.php seemed like it might > be > > > > the place to set like so: > > > > > > Configure::write('User.Address',$_SERVER['REMOTE_ADDR']); > > > > > > but it looks like that method only wants text strings for the write > > > > method and anyhow it did not work whether I tried it at top of > > > > app_controller.php or in a beforeFilter function in > > > > app_controller.php. > > > > > > I also tried more generic means such as using PHP getenv like so: > > > > > > $ipaddr = getenv('REMOTE_ADDR'); > > > > > > and that partly works, but I am not seeing a way to make it glovally > > > > available. Using the form > > > > > > var $ipaddr = getenv('REMOTE_ADDR'); > > > > > > at top of app_controller.php just does not work, but I am guessing I > > > > am misusing that "var" construct. > > > > > > Any thoughts welcome! > > > > > > J > > > > > > -- > > > > 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 > -- 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: Using Configure or other methods to set app-wide "constants"
http://techversys.com";>Techversys -- 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: Using Configure or other methods to set app-wide "constants"
You can use a simple way in app_controller like var $ipaddr=$_SERVER['REMOTE_ADDR']; and access in any controller function like: echo $this->ipaddr; On Jan 2, 7:12 pm, geste wrote: > Gary, euromark, > > OK, yes I was able use Configure::write in boostrap.php. > > If I can just use the CakePHP database connector, I think I'll just > write a small snippet that looks up that secondary identifier and add > that to bootstrap.php. > > Thanks, > > J > > On Jan 2, 2:35 pm, bujanga wrote: > > > > > > > > > This is really not a configuration item, though you can set it using > > Configure::write(). Of course, $_SERVER['REMOTE_ADDR'] must be > > provided by your web > > server.http://php.net/manual/en/reserved.variables.server.php > > If you are trying to create a user setting, a session cookie would be > > much more appropriate. Alternatively, I often log the user's IP > > address to the DB upon login. > > > Gary > > > On Mon, Jan 2, 2012 at 3:48 PM, geste wrote: > > > All, > > > > I am looking for the easiest, most global way to set a couple of app- > > > wide constants, more or less, that would derive from Apache variables, > > > specifically $_SERVER['REMOTE_USER'] and $_SERVER['REMOTE_ADDR'] and > > > that would be used throughout the app both in models and controllers. > > > > A Configure:write method in app_controller.php seemed like it might be > > > the place to set like so: > > > > Configure::write('User.Address',$_SERVER['REMOTE_ADDR']); > > > > but it looks like that method only wants text strings for the write > > > method and anyhow it did not work whether I tried it at top of > > > app_controller.php or in a beforeFilter function in > > > app_controller.php. > > > > I also tried more generic means such as using PHP getenv like so: > > > > $ipaddr = getenv('REMOTE_ADDR'); > > > > and that partly works, but I am not seeing a way to make it glovally > > > available. Using the form > > > > var $ipaddr = getenv('REMOTE_ADDR'); > > > > at top of app_controller.php just does not work, but I am guessing I > > > am misusing that "var" construct. > > > > Any thoughts welcome! > > > > J > > > > -- > > > 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: Using Configure or other methods to set app-wide "constants"
Gary, euromark, OK, yes I was able use Configure::write in boostrap.php. If I can just use the CakePHP database connector, I think I'll just write a small snippet that looks up that secondary identifier and add that to bootstrap.php. Thanks, J On Jan 2, 2:35 pm, bujanga wrote: > This is really not a configuration item, though you can set it using > Configure::write(). Of course, $_SERVER['REMOTE_ADDR'] must be > provided by your web > server.http://php.net/manual/en/reserved.variables.server.php > If you are trying to create a user setting, a session cookie would be > much more appropriate. Alternatively, I often log the user's IP > address to the DB upon login. > > Gary > > > > On Mon, Jan 2, 2012 at 3:48 PM, geste wrote: > > All, > > > I am looking for the easiest, most global way to set a couple of app- > > wide constants, more or less, that would derive from Apache variables, > > specifically $_SERVER['REMOTE_USER'] and $_SERVER['REMOTE_ADDR'] and > > that would be used throughout the app both in models and controllers. > > > A Configure:write method in app_controller.php seemed like it might be > > the place to set like so: > > > Configure::write('User.Address',$_SERVER['REMOTE_ADDR']); > > > but it looks like that method only wants text strings for the write > > method and anyhow it did not work whether I tried it at top of > > app_controller.php or in a beforeFilter function in > > app_controller.php. > > > I also tried more generic means such as using PHP getenv like so: > > > $ipaddr = getenv('REMOTE_ADDR'); > > > and that partly works, but I am not seeing a way to make it glovally > > available. Using the form > > > var $ipaddr = getenv('REMOTE_ADDR'); > > > at top of app_controller.php just does not work, but I am guessing I > > am misusing that "var" construct. > > > Any thoughts welcome! > > > J > > > -- > > 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: Using Configure or other methods to set app-wide "constants"
Thanks for your response. (This app can only be accessed via an Apache auth module that sets REMOTE_USER) On Jan 2, 2:13 pm, euromark wrote: > yes, you can use Configure::write() > that's absolute fine, but try to set it in bootstrap.php if they are > supposed to be global (side wide) > that would be a cleaner approach than using some AppController method > to do so. Yes, I am trying to determine the earliest point in the process where I can make these available. I was able to define a USERAADDR constant in bootstrap.php but had not tried Configure::Write there. (Which I will now do). I tried to keep my initial post simple, but one complication is that I also want to set anther global identifier that is kept in the application's user/person table. I am figure that I could just drop some one-off SQL query code in bootstarp.php, but thought I would try to do it the "Cake way" and so was trying to use existing model/ controller structure. J > > On 2 Jan., 22:48, geste wrote: > > > > > All, > > > I am looking for the easiest, most global way to set a couple of app- > > wide constants, more or less, that would derive from Apache variables, > > specifically $_SERVER['REMOTE_USER'] and $_SERVER['REMOTE_ADDR'] and > > that would be used throughout the app both in models and controllers. > > > A Configure:write method in app_controller.php seemed like it might be > > the place to set like so: > > > Configure::write('User.Address',$_SERVER['REMOTE_ADDR']); > > > but it looks like that method only wants text strings for the write > > method and anyhow it did not work whether I tried it at top of > > app_controller.php or in a beforeFilter function in > > app_controller.php. > > > I also tried more generic means such as using PHP getenv like so: > > > $ipaddr = getenv('REMOTE_ADDR'); > > > and that partly works, but I am not seeing a way to make it glovally > > available. Using the form > > > var $ipaddr = getenv('REMOTE_ADDR'); > > > at top of app_controller.php just does not work, but I am guessing I > > am misusing that "var" construct. > > > Any thoughts welcome! > > > J -- 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: Using Configure or other methods to set app-wide "constants"
This is really not a configuration item, though you can set it using Configure::write(). Of course, $_SERVER['REMOTE_ADDR'] must be provided by your web server. http://php.net/manual/en/reserved.variables.server.php If you are trying to create a user setting, a session cookie would be much more appropriate. Alternatively, I often log the user's IP address to the DB upon login. Gary On Mon, Jan 2, 2012 at 3:48 PM, geste wrote: > All, > > I am looking for the easiest, most global way to set a couple of app- > wide constants, more or less, that would derive from Apache variables, > specifically $_SERVER['REMOTE_USER'] and $_SERVER['REMOTE_ADDR'] and > that would be used throughout the app both in models and controllers. > > A Configure:write method in app_controller.php seemed like it might be > the place to set like so: > > Configure::write('User.Address',$_SERVER['REMOTE_ADDR']); > > but it looks like that method only wants text strings for the write > method and anyhow it did not work whether I tried it at top of > app_controller.php or in a beforeFilter function in > app_controller.php. > > I also tried more generic means such as using PHP getenv like so: > > $ipaddr = getenv('REMOTE_ADDR'); > > and that partly works, but I am not seeing a way to make it glovally > available. Using the form > > var $ipaddr = getenv('REMOTE_ADDR'); > > at top of app_controller.php just does not work, but I am guessing I > am misusing that "var" construct. > > Any thoughts welcome! > > J > > > > -- > 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: Using Configure or other methods to set app-wide "constants"
yes, you can use Configure::write() that's absolute fine, but try to set it in bootstrap.php if they are supposed to be global (side wide) that would be a cleaner approach than using some AppController method to do so. On 2 Jan., 22:48, geste wrote: > All, > > I am looking for the easiest, most global way to set a couple of app- > wide constants, more or less, that would derive from Apache variables, > specifically $_SERVER['REMOTE_USER'] and $_SERVER['REMOTE_ADDR'] and > that would be used throughout the app both in models and controllers. > > A Configure:write method in app_controller.php seemed like it might be > the place to set like so: > > Configure::write('User.Address',$_SERVER['REMOTE_ADDR']); > > but it looks like that method only wants text strings for the write > method and anyhow it did not work whether I tried it at top of > app_controller.php or in a beforeFilter function in > app_controller.php. > > I also tried more generic means such as using PHP getenv like so: > > $ipaddr = getenv('REMOTE_ADDR'); > > and that partly works, but I am not seeing a way to make it glovally > available. Using the form > > var $ipaddr = getenv('REMOTE_ADDR'); > > at top of app_controller.php just does not work, but I am guessing I > am misusing that "var" construct. > > Any thoughts welcome! > > J -- 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
Using Configure or other methods to set app-wide "constants"
All, I am looking for the easiest, most global way to set a couple of app- wide constants, more or less, that would derive from Apache variables, specifically $_SERVER['REMOTE_USER'] and $_SERVER['REMOTE_ADDR'] and that would be used throughout the app both in models and controllers. A Configure:write method in app_controller.php seemed like it might be the place to set like so: Configure::write('User.Address',$_SERVER['REMOTE_ADDR']); but it looks like that method only wants text strings for the write method and anyhow it did not work whether I tried it at top of app_controller.php or in a beforeFilter function in app_controller.php. I also tried more generic means such as using PHP getenv like so: $ipaddr = getenv('REMOTE_ADDR'); and that partly works, but I am not seeing a way to make it glovally available. Using the form var $ipaddr = getenv('REMOTE_ADDR'); at top of app_controller.php just does not work, but I am guessing I am misusing that "var" construct. Any thoughts welcome! J -- 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