<<-inserting records->>inserting records in a table is extremely easy with zephyr framework. all you have to do extra is creating a domain model of your table. for eaxmple lets see our sample table student.
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| name | varchar(255)| | | | |
| roll | int(11) | | | | |
| class | int | | | | |
+--------------+-------------+------+-----+---------+----------------+
now lets create our domain model. its a simple class describing all the fields you want to process except the "auto_increment" field. here is the domain for our sample student table. class student thats it!. now create a sample view in which user will input the data. <input type="text" id="name"> we will invoke insert_std() function [javascript] to process these records and passthem to an action which will insert our data. lets see this insert_std() function. NOTE THAT WE USED SAME ID AS OUR TABLE FIELD NAME IN THIS VIEW. function insert_std() this function just serialize all these values and invoke our action "insert_record". lets design that action. <?
in this action, load_db_domain() function simply loads the appropriate class for domain model. as we are using domain model "student", so we used load_db_domain("student") cls = auto_fill_domain("student"); the above line automatically fills the domain model with the values that user submits. now we just iunsert the data $query = $dao->insert(); all done, now just return all the students to user with recently inserted one. $students = $dao->selectBySQL("SELECT * FROM students"); <<-modifying and deleting records->>to update records all you have to do is just retrieve submitted data into a domain model and call "update()" mehtod of dao. lets see a sample action that updates the record. <?
here the only thing differs is that using the "update()" method. after filling the domain model with user input, you can "update()" method with a non optional where clause, here we use "roll = 1" which means that update the student where roll = 1. for deleting all you have to do using the delete() method of dao with same where clause. thats it. |