![]() |
|
Snippets |
|
creates an inplace editable html table from a database table. save this helper in your_project/lib/helper/input_in_place_editor_gridHelper.php dir
Special thanks to Christian.
There is a problem with saving the snippet here.I will try to update it later.
But for a normal (user interface) following action can be used:
public function executeUpdategrid() { $value=trim(strip_tags($_POST['value']));// new value of the cell being updated $pFieldValue=intval($this->getRequestParameter('pFieldValue'));// value of primary key of the record in the table, ie id value $fieldNo=intval($this->getRequestParameter('fieldNo'));// index of the field coming from input_in_place_grid_tag /* to permit the fields just we want to update here 2,3 and 4 are indexes of these fields in $rs, and this is for security this is used only if secure parameter is set in grid options */ # these are just examples to illustrate secure usage if($fieldNo==2) $fieldName='Account.FIRSTNAME'; elseif($fieldNo==3) $fieldName='Account.LASTNAME'; elseif($fieldNo==4) $fieldName='Account.BIRTHD'; elseif($fieldNo==5) $fieldName='Settings.EMAIL'; else die("Invalid Table Field!");// invalid field number.(just for security.Complete table field names can be used in an admin application) $split=explode(".",$fieldName); $tableName=$split[0]; // to find primary key field name $fields=call_user_func(ucfirst(strtolower($tableName)).'Peer::getFieldNames'); if($fields[0]) { # primary key field name $pFieldName=$tableName.".".strtoupper($fields[0]); # update corresponding field $conn=Propel::getConnection(); $sql="UPDATE $tableName SET $fieldName='$value' WHERE $pFieldName=$pFieldValue"; $conn->executeQuery($sql); $this->value=$value;// set the value to print out in the template "updategridSuccess.php" } else $this->value=null; }
or both can be used in same action as follows:
/** * account actions. * * @package 1insaat * @subpackage account * @author Ahmet Ertek * @version 1.0 * * @desc Implements input_in_place_editor_grid helper's cell update.(this helper is not standart, just a custom helper).This action is not in use now.See /profile/templates/settingsSuccess.php */ public function executeUpdategrid() { $value=trim(strip_tags($_POST['value']));// new value of the cell being updated $pFieldValue=intval($this->getRequestParameter('pFieldValue'));// value of primary key of the record in the table, ie id value $fieldNo=intval($this->getRequestParameter('fieldNo'));// index of the field coming from input_in_place_grid_tag $fieldName=trim($this->getRequestParameter('fieldName'));// name of the field to be updated $fieldName=str_replace("_",".",$fieldName);// replace _ with. This is because no_script_name can be setto "on" in settings.yml of app /* to permit the fields just we want to update here 2,3 and 4 are indexes of these fields in $rs, and this is for security this is used only if secure parameter is set in grid options */ if(!$fieldName) { # these are just examples to illustrate secure usage, change these field names with yours if($fieldNo==2) $fieldName='Account.FIRSTNAME'; elseif($fieldNo==3) $fieldName='Account.LASTNAME'; elseif($fieldNo==4) $fieldName='Account.BIRTHD'; elseif($fieldNo==5) $fieldName='Settings.EMAIL'; else die("Invalid Table Field!");// invalid field number.(just for security.Complete table field names can be used in an admin application) } $split=explode(".",$fieldName); $tableName=$split[0]; // to find primary key field name $fields=call_user_func(ucfirst(strtolower($tableName)).'Peer::getFieldNames'); if($fields[0]) { # primary key field name $pFieldName=$tableName.".".strtoupper($fields[0]); # update corresponding field $conn=Propel::getConnection(); $sql="UPDATE $tableName SET $fieldName='$value' WHERE $pFieldName=$pFieldValue"; $conn->executeQuery($sql); $this->value=$value;// set the value to print out in the template "updategridSuccess.php" } else $this->value=null; } ?>
Note that to use this grid for admin app you may use
$options['secure']=>false;