Introduction
Installation
Getting started
Package Definition Reference
Connecting to Database
Common DB Operations
Filter
Handling Multiple Databases
How-Tos
Deployment
Credit
Feedback
Changelog

Zephyr API

Forum

<<-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
{
    public $name;
    public $roll;
    public $class;
}

thats it!. now create a sample view in which user will input the data.

     <input type="text" id="name">
     <input type="text" id="roll">
     <input type="text" id="class">
     <input type="button" value=" = " onclick="insert_std();" />

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()
{
  serialized = group_serialize("name","roll","class");
  load_action_value('insert_record', serialized,'result');
}

this function just serialize all these values and invoke our action "insert_record". lets design that action.

<?
load_db_domain("student"); class insertstudent implements action { public $params ; public function execute() { $cls = auto_fill_domain("student"); $dao = new DAO($cls); $query = $dao->insert(); $students = $dao->selectBySQL("SELECT * FROM students"); $data = array("students"=>$students); return array("view_file"=>"liststudents", "data"=>$data); } } ?

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");
$data
= array("students"=>$students);
return array
("view_file"=>"liststudents", "data"=>$data);


<<-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.

<?
load_db_domain("student"); class updatestudent implements action { public $params ; public function execute() { cls = auto_fill_domain("student"); $dao = new DAO($cls); $query = $dao->update("roll=1"); $students = $dao->selectBySQL("SELECT * FROM students"); $data = array("students"=>$students); return array("view_file"=>"liststudents", "data"=>$data); } } ?

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.