![]() |
|
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;
This class allows ajax request content to be easily paginated with desired visual effect.
<?php /** @name ajaxpager.class.php @desc allows ajax pagination. $pager:pager object created using sfPropelPager $url:URL of desired action.(mostly current ajax action) $divId:id of div to be updated after pagination $params:extra parameters to send with pager (but not implemented yet.you can implement it by yourself) $appear_effect:visual effect on completing the request.(default is 'Appear').You can use also 'Grow' or 'SlideDown' etc. @author Ahmet ERTEK, erteka@gmail.com @copyright DVS Bilisim, www.dvs-tr.com @version 1.0.0 */ class ajaxpager { private $pager; private $divId; private $url; private $params; private $appear_effect; /** @name ajaxpager.class.php @desc allows ajax pagination. $pager:pager object created using sfPropelPager $url:URL of desired action.(mostly current ajax action) $divId:id of div to be updated after pagination $params:extra parameters to send with pager (but not implemented yet.you can implement it by yourself) $appear_effect:visual effect on completing the request.(default is 'Appear').You can use also 'Grow' or 'SlideDown' etc. @author Ahmet ERTEK, erteka@gmail.com @copyright DVS Bilisim, www.dvs-tr.com @version 1.0.0 */ public function ajaxpager($pager,$url,$divId,$params=null,$appear_effect='Appear') { $this->pager=$pager; $this->divId=$divId; $this->url=$url; $this->params=$params; $this->appear_effect=$appear_effect; } /** @name ajaxpager.class.php @desc prints pagination. @author Ahmet ERTEK, erteka@gmail.com @copyright DVS Bilisim, www.dvs-tr.com @version 1.0.0 */ public function printPager() { $pager=$this->pager; $url=$this->url; $divId=$this->divId; $appear_effect=$this->appear_effect; if ($pager->haveToPaginate()) { echo link_to_remote('«', array( 'update' => $divId, 'url' => $url.'?page='.$pager->getFirstPage(), 'complete'=>visual_effect($appear_effect, $divId), 'loading'=>"$('$divId').innerHTML='<img src=/images/indicator.gif border=0>'", ), array('class'=>'contentLink')); link_to_remote('<', array( 'update' => $divId, 'url' => $url.'?page='.$pager->getPreviousPage(), 'complete'=>visual_effect($appear_effect, $divId), 'loading'=>"$('$divId').innerHTML='<img src=/images/indicator.gif border=0>'", ), array('class'=>'contentLink')); $links = $pager->getLinks(); foreach ($links as $page) { echo($page == $pager->getPage()) ? $page : link_to_remote($page, array( 'update' => $divId, 'url' => $url.'?page='.$page, 'complete'=>visual_effect($appear_effect,$divId), 'loading'=>"$('$divId').innerHTML='<img src=/images/indicator.gif border=0>'", ), array('class'=>'contentLink')); if ($page != $pager->getCurrentMaxLink()){ echo "-"; } } echo link_to_remote('»', array( 'update' => $divId, 'url' => $url.'?page='.$pager->getNextPage(), 'complete'=>visual_effect($appear_effect, $divId), 'loading'=>"$('$divId').innerHTML='<img src=/images/indicator.gif border=0>'", ), array('class'=>'contentLink')); link_to_remote('>', array( 'update' => $divId, 'url' => $url.'?page='.$pager->getLastPage(), 'complete'=>visual_effect($appear_effect, $divId), 'loading'=>"$('$divId').innerHTML='<img src=/images/indicator.gif border=0>'", ), array('class'=>'contentLink')); } } } ?>
Usage:
<?php $ajax_pager=new ajaxpager($pager,'myDivId','account/pictures?id='.$accountId,null,'SlideDown'); $ajax_pager->printPager(); ?>