getCol()
methods.However you can do even more, you can even update or delete a Row. setCol()
methods e.g. If you have a Column called Counter You can execute $row->setCounter($row->getCounter()+1)
to specify the new value to that Column. update
that row will be updated. You need to pass a reference of tabl level Object to this method.e.g. $row->save($this->db->Student)
(For PHP4 Compatiability) $row->delete($this->db->Goods)
. remove method is an alias of delete method. Student
is instantiated into $this->db
as $this->db->Student
. so if we add some Custom method on Student Class we can invoke that from $this->db->Student
in our controller.
assume our Student table has a firstName and a lastName Column. so get get the Name of the student who's Id is 1 we need to execute $this->db->Student->findFirstNameById(1)." ".$this->db->Student->findLastNameById(1)
. But it would be better and easier too if you could use $this->db->Student->findNameById(1)
. But remember there is no such Column called name in our table.
To handle this situation you can add a method in your Student Class.
public function findNameById($id){ return $this->findFirstNameById($id)." ".$this->findLastNameById($id); }
$this->db->Student->findNameById(1)
which will return the Name of the student who's id is 1. $stdRowObj = $this->db->Student->findAllByPk(1)
now $stdRowObj is a Row Level object of Student table. so to get FirstName from it you can use $stdRowObj->getFirstName()
and to get Last Name you can use $stdRowObj->getLastName()
. But there is no such column Called Name. so to get Full Name you can use $stdRowObj->getFirstName()." ".$stdRowObj->getLastName()
. But It would be better if you can use just $stdRowObj->getName()
Instead.
As $stdRowObj
is an Instance of Student Class's row Level Class you can modify the StudentRowSet
Class and add an extra method to it called getName()
.
public function getName(){ return $this->getFirstName()." ".$this->getLastName(); }
$stdRowObj->getName()
the Custom method will be invoked. onInsert()
that method will be called just before an insert operation. the signature of teh function is onInsert($row)
the argument is optoional. Zigmoyd supplies a reference of an associative array of columns and their corresponding values to he method. You just need to change the values of the array if you want to do some final changes.
If you have a method onInsertCol($val)
that will be called just before inserting the date. e.g. If you have a Column called Email. and you want emails will always be stored as user at somesite dot com
format rathar than storing it raw.
You can create an onInsertEmail($val)
Trigger like the following.
public function onInsertEmail($val){ $val = str_replace(array('@', '.'), array(' at ', ' dot '), $val); }
If you have both RowLevel and column level Insert trigger both will be called. first the row level will be called and then column level will be calld.
onUpdate($row)
and onUpdateCol($val)
e.g if teh Column name is Email the trigger for that Column will be onUpdateEmail($value)
onDelete()
method it will be triggered just before any deleta Operation. user@somesite.com
format. Now what you want is whenever you retrive some data it will be in user at somesite dot com
you can simply create a trigger onExportEmail($val)
like this. public function onExportEmail($val){ $val = str_replace(array('@', '.'), array(' at ', ' dot '), $val); }
onExport($assoc)
, that accepts an associative array of key value pair. You just update some value there and it will reflect.