Insert Function in Symfony (How to save data of Form in to symfony)


We Can inset the relevant data sent from the form or any other refrence data like system date, author id from session variable.
First we need to know how to get the content of form in Model class.
The function Signature of Symfony is :
public function executeSaveCms(sfWebRequest $request) {
Here we can get the post or get request in this above function.
Get Request :

/* Here editId is get request which is sent from browser*/

Post Request :
/* Here contentTitle is input fields name form */
The request is assign in intermediate variable;
$content = $request->getPostParameter(‘ContentTitle’);

$c = new TBLCMS();
/* Create object for inserting table content Table name TBLCMS */
/* These below are the column name which set the content for the relevant column name */
/* The ContentDescription is column name which is CONTENT_DESCRIPTION*/
/*Finally we have to set the object to save function it will run the query with above relevent fields */


How to paginate the symfony list data


This is for listing the data in tabular format.

Module file  = <module_name/actions/actions.class.php>

/* 10 is constraint for list number of items */

$pager = new sfPropelPager(‘ClkPerPackageType’, 10);

/* this will get the page items which is defined in frontend/config/app.yml */
$c = new Criteria();
$pager->setPage($this->getRequestParameter(‘page’, 1));
$this->page_counter = ($this->getRequestParameter(‘page’, 1)==1) ? 1 : ((($this->getRequestParameter(‘page’)-1)*10)+1);
$this->ClkProductCompounds = $pager;




View file  = <templates/methodSuccess.php>

foreach ($ClkProductCompounds->getResults() as $cpc): ?>
<tr align=”left” <?php if($page_counter%2 ==0){ echo”style=’background-color:#e9e9e9;'”;}?>>
<td><?php echo $page_counter;?></td>
<td><?php echo $id = $cpc->getPerPackageTypeCode() ?></td>
<td><?php echo $cpc->getPerPackageTypeName(); ?></td>
<td><a href=”<?php echo url_for(‘PerPackageType/list?edit=’ . $id ); ?>”>edit</a></td>


Pagination list. It creates the page link to the fist list and page number.

<div class=”Paging”>
<?php if ($ClkProductCompounds->haveToPaginate()): ?>
<?php echo link_to(‘&laquo;’, ‘PerPackageType/list?page=1’) ?>
<?php echo link_to(‘&lt;’, ‘PerPackageType/list?page=’.$ClkProductCompounds->getPreviousPage()) ?>

<?php foreach ($ClkProductCompounds->getLinks() as $page): ?>
<?php echo link_to_unless($page == $ClkProductCompounds->getPage(), $page, ‘PerPackageType/list?page=’.$page) ?>
<?php echo ($page != $ClkProductCompounds->getCurrentMaxLink()) ? ‘-‘ : ” ?>
<?php endforeach; ?>

<?php echo link_to(‘&gt;’, ‘PerPackageType/list?page=’.$ClkProductCompounds->getNextPage()) ?>
<?php echo link_to(‘&raquo;’, ‘PerPackageType/list?page=’.$ClkProductCompounds->getLastPage()) ?>
<?php endif; ?>





Generate Url in Symfony framework

Generate Url   :: this->generateUrl():


This function can generate the url of the module as argument of the function and returns the module full url.



url_for(‘ProductCompound/view?edit=’ . $id );



How to add Style and Javascript pages on Symfony


We have the config file for including our styles and script file on symfony project.
which is View.yml file contained on Config folder.


Example :
stylesheets: [theme-brown0.0.1/main.css, theme-brown0.0.1/superfish.css, ui-smoothness/jquery-ui-1.8.2.custom.css, blueprint/plugins/buttons/screen.css, blueprint/screen.css,pharmacy.css]


javascripts:    [jquery-1.4.2.min.js,jquery-ui-1.8.2.custom.min.js,hoverIntent.js,superfish.js,supersubs.js,jquery.qtip-1.0.min.js,main.js,jquery.validate.min.js,jquery.tablesorter.min.js,functions.js,prototype.js, script.js,tiny_mce/tiny_mce.js,validation.js,scriptVar.js,pharmacy.js,validationPharmacy.js,pcsnepaliunicode.js]