Gelmiş geçmiş en büyük porno sitemiz olan 2pe de her zaman en kaliteli pornoları sunmayı hedefledik. Diğer video sitemiz olan vuam da ise hd porno ağırlıklı çalışmalara başladık.

  1. #1
    Sencha User Boston's Avatar
    Join Date
    Oct 2011
    Posts
    27
    Answers
    3
    Vote Rating
    0
    Boston is on a distinguished road

      0  

    Default Answered: How to update a databse?

    Answered: How to update a databse?


    Hi,

    I'm new on ExtJS and try to write an app which updates a record in a Database, using a PHP backend.

    I started with the MVC example on this website. Reading the data works nearly fine.  I only get the notice "Store defined with no model. You may have mistyped the model name." since I'm using 4.0.7. Anyway the data is written in the grid.

    After a dblclick a window with the record is opend. The record can be edited and is updated in the grid.

    But when I try an update I face the error message "uncaught exception: You are using a ServerProxy but have not supplied it with a url."

    I'm afraid that it is a typical mistake of an ExtJS beginner but I hope that anyone can help so that I can go forward.

    Here my code:

    Controller:
    Code:
    Ext.define('AM.controller.Haendler', {
        extend: 'Ext.app.Controller',
    
        views: [
            'user.HListe',
            'user.HEdit',
            'user.NavTree'
        ],
        
        stores: [
            'Haendler'
        ],
        
        models: [
            'HaendlerAdr'
        ],
    
        init: function() {
            this.control({
                'haendlerliste': {
                    itemdblclick: this.edithaendler
                },
                'edithaendler button[action=save]': {
                    click: this.updatehaendler
                }
    
            });
        },
    
        edithaendler: function(grid, record) {
            var view = Ext.widget('edithaendler');
    
            view.down('form').loadRecord(record);
        },
    
        updatehaendler: function(button) {
            var win    = button.up('window'),
                form   = win.down('form'),
                record = form.getRecord(),
                values = form.getValues();
    
            record.set(values);
            win.close();
            this.getHaendlerStore().sync();
            
        }
    });
    Store:
    Code:
    Ext.define('AM.store.Haendler', {
        extend: 'Ext.data.Store',
        model: 'AM.model.HaendlerAdr',
        autoLoad: true,
    
        proxy: {
            type: 'ajax',
            api: {
                read: 'http://tools.example.com/ExtJS/php/backend.php?task=anzeigen',
                update: 'http://tools.example.com/ExtJS/php/backend.php?task=aktualisieren'
            },
            reader: {
                type: 'json',
                root: 'results',
                successProperty: 'success'
            }
        }
    });
    Model:
    Code:
    Ext.define('AM.model.HaendlerAdr', {
        extend: 'Ext.data.Model',
        fields: ['ID','Name', 'Inhaber'],
        proxy: {
            type: 'ajax',
            api: {
                read: 'http://tools.example.com/ExtJS/php/backend.php?task=anzeigen',
                update: 'http://tools.example.com/ExtJS/php/backend.php?task=aktualisieren'
            },
            reader: {
                type: 'json',
                root: 'results',
                successProperty: 'success'
            }
        }
    });
    Grid:
    Code:
    Ext.define('AM.view.user.HListe' ,{
        extend: 'Ext.grid.Panel',
        alias : 'widget.haendlerliste',
        width: 400,
        x: 10,
        y: 20,
        title : 'Händler (Übersicht)',
        store: 'Haendler',
        collapsible: true,
        collapseDirection: 'top',
        titleCollapse: true,
        dockedItems: [{
            xtype: 'pagingtoolbar',
            store: 'Haendler',
            dock: 'bottom',
            emptyMsg: "Keine Daten übermittelt",
            displayInfo: true
        }],
        initComponent: function() {
    
            this.columns = [
                {header: 'ID',  dataIndex: 'ID',  flex: 1},
                {header: 'Name',  dataIndex: 'Name',  flex: 1},
                {header: 'Inahber', dataIndex: 'Inhaber', flex: 1}
            ];
    
            this.callParent(arguments);
        }
    });
    Window:
    Code:
    Ext.define('AM.view.user.HEdit', {
        extend: 'Ext.window.Window',
        alias : 'widget.edithaendler',
    
        title : 'Händler bearbeiten',
        layout: 'fit',
        autoShow: true,
    
        initComponent: function() {
            this.items = [
                {
                    xtype: 'form',
                    items: [
                        {
                            xtype: 'textfield',
                            name : 'Name',
                            fieldLabel: 'Name'
                        },
                        {
                            xtype: 'textfield',
                            name : 'Inhaber',
                            fieldLabel: 'Inhaber'
                        }
                    ]
                }
            ];
    
            this.buttons = [
                {
                    text: 'Speichern',
                    action: 'save'
                },
                {
                    text: 'Abbruch',
                    scope: this,
                    handler: this.close
                }
            ];
    
            this.callParent(arguments);
        }
    });

  2. Thanks to all for your advices.

    But the final hint I fonud here (after you gave me the hint I should look for):
    http://www.sencha.com/forum/showthre...date-a-databse

  3. #2
    Sencha User
    Join Date
    Oct 2010
    Location
    Brazil - MG, Belo Horizonte
    Posts
    62
    Answers
    4
    Vote Rating
    0
    wallynm is on a distinguished road

      0  

    Default


    Well, about the error, i will try to see what could be happeing, but, i found an error on your code:
    Code:
    Ext.define('AM.model.HaendlerAdr', {   
        extend: 'Ext.data.Model',
        fields: ['ID','Name', 'Inhaber'],
        proxy: {
            type: 'ajax',
            api: {
                read: 'http://tools.example.com/ExtJS/php/backend.php?task=anzeigen',
                update: 'http://tools.example.com/ExtJS/php/backend.php?task=aktualisieren'        },
            reader: {
                type: 'json',
                root: 'results',
                successProperty: 'success'
            }
        }
    });
    you don't need to define your proxy again on the mode, your store wil handle all url requests from the grid.
    just set your model as here:
    Code:
    Ext.define('AM.model.HaendlerAdr', { 
        extend: 'Ext.data.Model',    
        fields: ['ID','Name', 'Inhaber']
    });

  4. #3
    Sencha User Boston's Avatar
    Join Date
    Oct 2011
    Posts
    27
    Answers
    3
    Vote Rating
    0
    Boston is on a distinguished road

      0  

    Default


    Hi wallynm,

    thanks for the hint. But I placed the additinal proxy definition after I got the error message. My first version looked like yours.

  5. #4
    Sencha User
    Join Date
    Dec 2009
    Location
    Enschede, The Netherlands
    Posts
    327
    Answers
    16
    Vote Rating
    13
    flanders will become famous soon enough

      0  

    Default


    With regards to "But when I try an update I face the error message "uncaught exception: You are using a ServerProxy but have not supplied it with a url."" this quite a descriptive message imho.

    The documentation for Ext.data.proxy.Ajax (which extends the serverproxy) shows a configuration property 'url' that needs to be provided. Like this:

    Code:
    Ext.define('AM.model.HaendlerAdr', {
           extend: 'Ext.data.Model',
          fields: ['ID','Name', 'Inhaber'],
          proxy: {
             type: 'ajax',
             api: {
                read: '?task=anzeigen',
                update: '?task=aktualisieren'
              },
             reader: {
                type: 'json',
                root: 'results',
                successProperty: 'success'
             },
             url: 'your/url'
        }
    });
    Furthermore I would advise defining the proxy on the model and not on the store. This alows for using single instances of the model w/o a store (and reusing that proxy when working with an store) Not trying to start a flame war, but thought i point to the alternative
    Last edited by flanders; 22 Nov 2011 at 11:45 AM. Reason: I'm gonna smack a brick at that editor..

  6. #5
    Sencha User Boston's Avatar
    Join Date
    Oct 2011
    Posts
    27
    Answers
    3
    Vote Rating
    0
    Boston is on a distinguished road

      0  

    Default


    Thanks to all for your advices.

    But the final hint I fonud here (after you gave me the hint I should look for):
    http://www.sencha.com/forum/showthre...date-a-databse

Thread Participants: 2