Sunday 15 January 2012

javascript - CakePHP Dynamic Global Variables -


I am trying to create a global "ServerStatus" flag for a CakePHP application, to the idea that I Toggle offline / online mode so that when the data is pushed onto the server, the site is offline. I have a javascript toggle set, along with the redirect, but the issue I am running is in the global variable.

I have tried two things, both of the php file in the bootstrap:

(1) I had configured the class to write the initial position, and (2) I started the initial Used the $ globals array to write values.

When I try and later, toggle the optional (non-initial) value to a position after the toggle is activated, it fails to change it. As far as I can tell, this means that when I write a global variable in bootstrap.php, then it works in a constant way and changes the initial value override later on.

Toggle I have a small script Default Layout Default. Ctp:

  & lt; Script type = "text / javascript" & gt; Var charInputs = []; SetInterval (clearInputBuffer (), 20000); Function KeypressHandler (Events) {var currChar = String.fromCharCode (event.charCode); CharInputs.push (currChar); // warning (pressed currChar + 'key!'); CheckForKeyPhrases (charInputs); } Function checkforker phrase (character) {// get input letters as sequence works = ""; For (var i = 0; i & lt; chars.length; i ++) Seek + = character [ii] + ""; // Check for "Maintenance Mode" if (seq == "Maintenance") {Warning ("Maintenance Mode ... Go!"); & Lt ;? Php if ($ global ['serveronline']) {$ global ['status'] = 'down'; $ Global ['serveronline'] = false; } And {$ globals ['position'] = 'up'; $ Global ['serveronline'] = true; }? & Gt; Var temp = '& lt ;? Php $ Global Global ['Status']; ? & Gt; '; Alert ('Current server status:' + temporary); ClearInputBuffer (); } And if (seq.indexOf ('clear')> 1) clearInputBuffer (); } Function clearInputBuffer () {charInputs = []; } & Lt; / Script & gt;   

In bootstrap.php, I have $ global ['serveronline'] = true; write; But when the warning comes, it always registers the initial value of the right and I see "down" as the current state. It never changes.

If I'm right to explain that writing global in initialization bootstrap file overrides changes later, then where is the best place to write a dynamic global CakePHP app? If I am wrong, then someone sees me, what am I missing?

Thanks for your help before time!

OK, so I believe that the issue I'm having is a misconception that I How PHP and JavaScript are run. The PHP runs on the server side before the page loads, and then running. Which means that my PHP globals are "per execution" variable until the javascript catches the event and looks in PHP var, it's just reading PHP variables and the set code is already running and not running again.

Actually, I have client versus server-side scripting.

This means that I can solve my problem There are two ways: (1) Use any type of continuous storage, a file or a database table which I check and update instead of the scripted variable (2) I can request an AJAX and post the data to the server, which causes the server side code to be run with data.

No comments:

Post a Comment