K..
K..

Reputation: 4233

ExtJS 4 extending Ext.data.Connection

I tried to extend the Connection class, like Ext.Ajax did to get a central point where I can set some default values.

  Ext.define( 'App.helper.HttpApi', {
    extend   : 'Ext.data.Connection',
    singleton: true,

    request: function( oConf ) {

      oConf.url = '/index.php';
      oConf.params.vers = '1.1.json';
      oConf.params...

      this.callParent( oConf );
    }
  } );

I get : "Uncaught Ext.Error: No URL specified" But as you can see, the url IS specified... somehow it gets lost in the depth of the Ext Code.

Upvotes: 0

Views: 2091

Answers (1)

Saket Patel
Saket Patel

Reputation: 6683

the error which you are getting is thrown by setOptions method of Ext.data.Connection

so you need to provide url when constructor of Ext.data.Connection is called so all further methods can use that url

Ext.define( 'App.helper.HttpApi', {
    extend   : 'Ext.data.Connection',
    singleton: true,

    constructor : function (config)
    {
        config = config || {};
        Ext.applyIf(config, {
            url : '/index.php'
        });

        this.callParent(config);
    },

    request: function( oConf ) {
      oConf.params.vers = '1.1.json';
      oConf.params...

      this.callParent( oConf );
    }
});

or if you are going to use single url for all the requests then you can directly specify it as default value of this singleton

Ext.define( 'App.helper.HttpApi', {
    extend   : 'Ext.data.Connection',
    singleton: true,
    url : '/index.php',

    request: function( oConf ) {
      oConf.params.vers = '1.1.json';
      oConf.params...

      this.callParent( oConf );
    }
});

Upvotes: 1

Related Questions