1. #41
    Ext JS Premium Member
    Join Date
    Mar 2007
    Posts
    12
    Vote Rating
    0
    padawan is on a distinguished road

      0  

    Default


    Just want to say thank you for sharing this. Although I have been using extjs for some time now, I am far from being an expert. But anywayz, I think this Ext.Direct implementation is great!

  2. #42
    Ext JS Premium Member
    Join Date
    May 2008
    Posts
    374
    Vote Rating
    13
    ttbgwt will become famous soon enough

      0  

    Default


    Do you have an example of how to use the authorize function? And how to send username and password encrypted to it?

  3. #43
    Sencha User walldorff's Avatar
    Join Date
    Mar 2008
    Location
    Antwerp, Belgium
    Posts
    164
    Vote Rating
    2
    walldorff is on a distinguished road

      0  

    Default [SOLVED] $_POST as empty array

    [SOLVED] $_POST as empty array


    In the form I have the api config option set to 2 functions: load (which successfully load a string into the field) and submit (where I get an error from my custom class, complaining about an empty object in the parameter).

    Demo: http://extme.eu/DirectTest/

    PHP Code:
    // the body part of the index.php
    <body>
        <
    script type="text/javascript" src="Numbers.php?javascript"></script>
        <script type="text/javascript" src="form.js"></script>
    </body> 
    PHP Code:
    <?php
    // the class
    require 'ExtDirect.php';

    class 
    Numbers {
        public function 
    validate($data) {
            
    // $_POST is empty!
            // error: 'Cannot use object of type stdClass as array'
            
    $num $data['num'];
            
    $response = array('success' => true);
            if (!
    is_numeric($num)) {
                
    $response['success'] = false;
                
    $response['errors']  = array(
                    
    'num'=>'Not a valid number.'
                
    );
            }
            return 
    $response;
        }

        public function 
    load($id) {
            return 
    'loaded: '.$id;
        } 
    }

    ExtDirect::provide('Numbers');
    ExtDirect::$form_handlers = array( 'Numbers::validate');
    ?>
    PHP Code:
    // form.js
    Ext.ns('Ext.php');
    Ext.onReady(function () {
        
    Ext.QuickTips.init();

        
    Ext.php.callback = function (responsee) {
            if (
    true === e.status) {
                
    Ext.php.formExample.items.items[0].setValue(response);
            }
        };

        
    Ext.php.formExample = new Ext.form.FormPanel({
            
    title'Validation Form'
            
    ,monitorValidtrue
            
    ,renderToExt.getBody()
            ,
    padding10
            
    ,height:120
            
    ,width:300
            
    ,buttons:[{
                
    text'Validate'
                
    ,handler: function(){
                    
    Ext.php.formExample.getForm().submit();
                }
            }]
            ,
    items: [{
                
    fieldLabel'Enter a number'
                
    ,xtype'textfield'
                
    ,name'num' // also tried with id: 'num'
                
    ,msgTarget'side'
                
    ,allowBlank:false
            
    }]
            ,
    api: {
                
    loadExt.php.Numbers.load('loadtest'Ext.php.callback)
                ,
    submitExt.php.Numbers.validate
            
    }
        });
    }); 
    Obviously the class receives an empty array; where does that come from? Even the $_POST array is empty.
    In get_request_actions() (line 274) the foreach tries to access $rpc->$variable. Is this correct?
    PHP Code:
    $$variable = ( isset( $rpc->$variable ) ? $rpc->$variable '' ); 
    I tried with ExtDirect::$default_api_output = "javascript", ExtDirect::$instantiate_static = true, ExtDirect::$include_inherited_methods = true and almost every other config setting.
    I would be grateful for a kick in the right direction.
    Attached Images
    Last edited by walldorff; 28 Dec 2010 at 1:00 AM. Reason: Solved
    ExtJS 3.4, WAMP Apache 2.2.17, PHP 5.3.5, MySQL 5.5.8

  4. #44
    Sencha User
    Join Date
    Mar 2010
    Posts
    47
    Vote Rating
    0
    Andrew Peacock is on a distinguished road

      0  

    Default


    // $_POST is empty!
    // error: 'Cannot use object of type stdClass as array'


    Doesn't that mean that you should be using:

    Code:
     $num = $data->num; 
    ?

    Regards,
    Andy


  5. #45
    Sencha User walldorff's Avatar
    Join Date
    Mar 2008
    Location
    Antwerp, Belgium
    Posts
    164
    Vote Rating
    2
    walldorff is on a distinguished road

      0  

    Default


    Quote Originally Posted by Andrew Peacock View Post
    Doesn't that mean that you should be using:
    Code:
     $num = $data->num; 
    Thanks Andy. If you run the demo with Firebug, you'll notice that the data is an empty object. The PHP class method should get a $_POST as an array, but also this is empty. Its puzzling. It's a simple form, it should submit simple data, only one field. In other test environment this form runs ok.
    ExtJS 3.4, WAMP Apache 2.2.17, PHP 5.3.5, MySQL 5.5.8

  6. #46
    Sencha User
    Join Date
    Mar 2010
    Posts
    47
    Vote Rating
    0
    Andrew Peacock is on a distinguished road

      0  

    Default


    OK, you got me stumped so I had a play around.

    Change:

    Code:
    ExtDirect::provide('Numbers'); 
    ExtDirect::$form_handlers = array( 'Numbers::validate');
    to

    Code:
    ExtDirect::$form_handlers = array( 'Numbers::validate');
    ExtDirect::provide('Numbers'); 
    
    I think the provide has to go last!

    Also, check the comments here about "receiving parameters":
    http://www.sencha.com/forum/showthre...078#post484078

    This means your PHP function definition would be:

    Code:
    public function validate($num) {
    Hope that helps!
    Andy

  7. #47
    Sencha User walldorff's Avatar
    Join Date
    Mar 2008
    Location
    Antwerp, Belgium
    Posts
    164
    Vote Rating
    2
    walldorff is on a distinguished road

      0  

    Thumbs up terrific!

    terrific!


    Andy, that was it!
    Your suggestion to switch the call to the ExtDirect methods did the trick.
    The call to ExtDirect::provide() apparently has to be the last call in the sequence, which seems perfectly logical. I can't believe I missed that.

    Thank you so much for your help!

    Roland
    ExtJS 3.4, WAMP Apache 2.2.17, PHP 5.3.5, MySQL 5.5.8

  8. #48
    Sencha User
    Join Date
    Mar 2010
    Posts
    47
    Vote Rating
    0
    Andrew Peacock is on a distinguished road

      0  

    Default


    No problem! Glad to help
    Andy

  9. #49
    Sencha User
    Join Date
    Apr 2010
    Posts
    9
    Vote Rating
    0
    tiagoadp is on a distinguished road

      0  

    Question Any updated for ext 4.0 ???

    Any updated for ext 4.0 ???


    Hello, are you planning any updates for ext 4.0?

    I tryed to solve the problems by myself on the "PR" and now on "BETA 1", but i couldĀ“t do it...

    Any update will be most wellcome...

  10. #50
    Touch Premium Member
    Join Date
    Jun 2008
    Location
    Germany, Dortmund
    Posts
    249
    Vote Rating
    13
    hschaefer123 will become famous soon enough

      0  

    Default


    Hi J.Bruni,
    i love your Ext.Direct implementation.

    After playing around with SAKI's Ext Direct HTTP State Provider and realizing the Implementation of
    examples/state/SessionProvider.js

    I figured out, that this kind of implementation perfectly fits into your Direct Implementation.
    That means, your implementation will also be able to save and restore component ui state information.

    To make this working i added i modified the javascript api
    Code:
        /**
         * @return string   JSON encoded array containing the full API declaration
         */
        static public function get_api_javascript()
        {    
            session_start();        
            //unset($_SESSION['extjsstate']);
            if(!isset($_SESSION['extjsstate'])){
                $_SESSION['extjsstate'] = array(
                    'sessionId'=>session_id()
                );
            }
        
            $template = <<<JAVASCRIPT
    
    Ext.namespace( '[%namespace%]' );
    [%descriptor%] = [%actions%];
    Ext.Direct.addProvider( [%descriptor%] );
    Ext.appState = [%appstate%];
    
    JAVASCRIPT;
            
            $elements = array(
                '[%actions%]'    => self::get_api_json(),
                '[%namespace%]'  => ExtDirect::$namespace,
                '[%descriptor%]' => ExtDirect::$descriptor,
                '[%appstate%]' => json_encode($_SESSION['extjsstate'])
            );
            
            return strtr( $template, $elements );
        }
    i also added some code at the end of
    protected function get_request_actions()
    Code:
            // handle state
            session_start();
            if(!isset($_SESSION['extjsstate'])){
                $_SESSION['extjsstate'] = array(
                    'sessionId'=>session_id()
                );
            }
            foreach($_COOKIE as $name=>$value){
                // look for state cookies
                if(strpos($name, 'ys-') === 0){
                    // store in session
                    $_SESSION['extjsstate'][substr($name, 3)] = urlencode($value);
                    // remove cookie
                    setCookie($name, '', time()-10000, '/');
                }
            }
    and that's it.

    The only thing to do is to initialize StateManager onReady
    Code:
    Ext.onReady(function() {
        ...
        Ext.state.Manager.setProvider(
           new Ext.state.SessionProvider({state: Ext.appState})
        ); 
        ... init code
    Now the API include contains a new variable holding the state info
    Ext.appState = {"sessionId":"9e7f3v1vbcrf5r45j3hb28g8p2","MyDirectoryGrid":"o%3Acolumns%3Da%25...."};

    Now if something is changed inside ui, the next roundtrip through Ext.Driret Router the UI State will be catched from COOKIE and stores inside PHP Session (Serverside instead of Client Side implementation).

    My kind of implementation is only for demo/testing. Maybe you can implement such feature via new toogle Property and callBack function (like auth) to make implementation of individually store containers for session data possible (maybe mySQL or SQLite).

    I think, that would be a great addon to your fantastic implementation.

    Cheers,
    Holger