PDA

View Full Version : Variables ExtJS and PHP



jailsonjan
19 Apr 2013, 6:19 AM
hello guys,

I need to transfer a value from a variable between pages and tabs.

I've tried starting this variable "idxz" through "Ext.define", but the value is not changed properly, kept the overall value or presented not defined.

Now, I am trying to transfer the contents of a variable "Extjs", which has a numerical value, generated by a "getValue", to a PHP variable and I'm not getting, because it does not pass the correct value, just pass the name of the variable.

In "console.log", the values ??appear correctly.
What is the correct way to associate this value to PHP "$IDXZ" variable?
Help me!




listeners: {
singleton: true,
selectionchange: function(model, records, grid, rowIndex, columnIndex, editEvent, e) {
if (records[0]) {
this.up('form').getForm().loadRecord(records[0]);

}
},

itemclick: function teste(view, record, item, index, e, eOpts){
singleton: true,

console.log ('------ grid clicada ----------');


var zen= Ext.getCmp('id').getValue();

Init.idxz=zen;
idxz = Ext.JSON.encode(zen);

<?php $IDXZ=" ??????????????????????????????????????????" ?>

console.log ('['+zen+'|'+Init.idxz+'|'+idxz+']');

},

} // End of Listers

slemmon
20 Apr 2013, 10:37 PM
Normally you're running ExtJS from a browser which will work with the Javascript and PHP from the server. Are you running the ExtJS script on the server with your PHP scripts?

jailsonjan
22 Apr 2013, 7:10 AM
Normally you're running ExtJS from a browser which will work with the Javascript and PHP from the server. Are you running the ExtJS script on the server with your PHP scripts?

Slemmon, I running Extjs inside a Php file in this moment.

jailsonjan
22 Apr 2013, 10:19 AM
Extjs to call a variable to a PHP simply associate this:
$idxzero="'+parseInt(zenx)+'";


I found another post on this forum a way to initialize a global variable, I managed to make a partial solution for my case.



Ext.define('MySharedData', {
singleton: true,
idxz: 6,
});


In other part of my code i take the variable:



src: 'remotegrid.php?iddoevento='+MySharedData.idxz,


This is functional, but how to change the value of the variable initialized inside the Ext.define?


When I do the initialization of a variable:



MySharedData.idxz=zen;


The value don't change. Any idea?

Arg0n
23 Apr 2013, 8:23 AM
What the hell xD

1. PHP runs one time. So when site is finished all PHP variables and objects are gone in oblivion.
2. JS runs as long as the site is open.
3. Never execute JS with PHP o.O

Thats why JS runs asynchron to PHP. To pass variables to php and back Ajax was introduced. You should be clear about that first. To store values in your backend you need some kind of a database.

Now please explain what exactly you want to do :x

jailsonjan
23 Apr 2013, 8:52 AM
Thanks for the replies slemmon and Arg0n.

I know js is asynchron, which runs in the browser and php in the server.
My problem is not there.
I have a page that contains a "listeners" that associates a value to a variable.
This variable is declared and initiated through a "Ext.define" (global) in the top of page.
Elsewhere on the same page, I want to retrieve the value of this variable, which already got.
At this moment let's forget php.
The problem is: How to change the value of this variable (Extjs), through the changed value by "listeners".:D

Arg0n
23 Apr 2013, 11:57 AM
You should be clear about what Ext.define is doing: http://docs.sencha.com/extjs/4.1.3/#!/api/Ext-method-define

It's for defining classes not for defining global variables. So you defined a singleton class with the name 'MySharedData'. Singleton means, you can not create multiple instances of this class. There will be only one. And this can be accessed from anywhere.

With your example you would have to require the class first, so that the Ext.Loader (http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.Loader) knows about it. You can do it with:


Ext.require('MySharedData');

After that you can access your variable from anywhere with:


MySharedData.idxz;

BUT!

That's not the way to do it. It's like driving a car with a square steeringwheel. For storing global data you can and should use a store:



Ext.create('Ext.data.Store', {
data : [
{id: 'XY', value: 'Foo'}
],
storeId: 'myData'
});

Then you can get the store with:


var store = Ext.getStore('myData');

And get the data with:


store.findRecord('id', 'XY').get('value');

:P