I do quite a lot of insertions and have used the method outlined in 'How_To_Use_The_Database_classes ...' which works if used correctly. But I notice that Max uses a different approach in Chronoforms (See the autogenerated code for a form which uses a database). I can almost, but not quite, follow the system he is using.
He is getting variables using 'Jrequest::getvar and adding them to the post with Jrequest::Setvar and 'binding them to a 'row' which seems to be a sort of blank template of the columns of the table.
But my question is
Which method is better or faster or in other word why use this method ?? I am learning !!
--
Dave
He is getting variables using 'Jrequest::getvar and adding them to the post with Jrequest::Setvar and 'binding them to a 'row' which seems to be a sort of blank template of the columns of the table.
But my question is
Which method is better or faster or in other word why use this method ?? I am learning !!
--
Dave
Hi Dave,
Joomla supports a Model, View, Controller (MVC) architecture in the main framework and this in turn has some methods that enable database saving.
Essentially you define a Tables class which identifies the table columns, then in the Model class there are default methods bind(), check() and store() - possibly save() too.
The bind() method associates an array to the table columns using matching field-names.
The check() method can run validation on the results.
The store() method saves the result to the database using INSERT forn new IDs or REPLACE if the id already exists in the table.
This is a very elegant and effective approach and one that Max uses now in the Autogenerated Code. He actually saves the definition of the Form Table Object in the database when you set up a DB Conenction and recreates the object when the form is submitted.
This works very well for 'simple' requests and can be elaborated for more complicated ones by adding extra methods to the model class (Max doesn't formally use the Model class but you can see it in other extensions).
Hoewever, it's not easy to explain and it's really not for PHP novices. Standard MySQL queries are less elegant but they are much easier to understand and to debug when things go wrong. I tend to use them most of the time in developing with ChronoForms of ChronoConnectivity - though I use the MVC approach when writing custom extensions.
Not sure how much this helps but it might give you more of an idea. Both approaches will work, both have advantages and disadvantages.
Bob
Joomla supports a Model, View, Controller (MVC) architecture in the main framework and this in turn has some methods that enable database saving.
Essentially you define a Tables class which identifies the table columns, then in the Model class there are default methods bind(), check() and store() - possibly save() too.
The bind() method associates an array to the table columns using matching field-names.
The check() method can run validation on the results.
The store() method saves the result to the database using INSERT forn new IDs or REPLACE if the id already exists in the table.
This is a very elegant and effective approach and one that Max uses now in the Autogenerated Code. He actually saves the definition of the Form Table Object in the database when you set up a DB Conenction and recreates the object when the form is submitted.
This works very well for 'simple' requests and can be elaborated for more complicated ones by adding extra methods to the model class (Max doesn't formally use the Model class but you can see it in other extensions).
Hoewever, it's not easy to explain and it's really not for PHP novices. Standard MySQL queries are less elegant but they are much easier to understand and to debug when things go wrong. I tend to use them most of the time in developing with ChronoForms of ChronoConnectivity - though I use the MVC approach when writing custom extensions.
Not sure how much this helps but it might give you more of an idea. Both approaches will work, both have advantages and disadvantages.
Bob
This topic is locked and no more replies can be posted.