Results 1 to 7 of 7

Thread: Variables ExtJS and PHP

  1. #1
    Sencha User
    Join Date
    Apr 2012
    Location
    Porto Alegre - Brazil
    Posts
    11

    Default Variables ExtJS and PHP

    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!


    Code:
    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

  2. #2
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505

    Default

    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?

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Location
    Porto Alegre - Brazil
    Posts
    11

    Default

    Quote Originally Posted by slemmon View Post
    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.

  4. #4
    Sencha User
    Join Date
    Apr 2012
    Location
    Porto Alegre - Brazil
    Posts
    11

    Default

    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.

    Code:
    Ext.define('MySharedData', {
            singleton: true,
            idxz: 6,
       });
    In other part of my code i take the variable:

    Code:
    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:

    Code:
    MySharedData.idxz=zen;
    The value don't change. Any idea?

  5. #5
    Sencha User Arg0n's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    122
    Answers
    12

    Default

    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

  6. #6
    Sencha User
    Join Date
    Apr 2012
    Location
    Porto Alegre - Brazil
    Posts
    11

    Default

    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".

  7. #7
    Sencha User Arg0n's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    122
    Answers
    12

    Default

    You should be clear about what Ext.define is doing: http://docs.sencha.com/extjs/4.1.3/#...-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 knows about it. You can do it with:

    Code:
    Ext.require('MySharedData');
    After that you can access your variable from anywhere with:

    Code:
    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:

    Code:
    Ext.create('Ext.data.Store', {
        data : [         
            {id: 'XY',    value: 'Foo'}     
        ],    
        storeId: 'myData'  
    });
    Then you can get the store with:

    Code:
    var store = Ext.getStore('myData');
    And get the data with:

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •