Sep.28

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

INSERT_QUERY

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 :

$request->getParameter(‘editId’);
/* Here editId is get request which is sent from browser*/

Post Request :
$request->getPostParameter(‘ContentTitle’);
/* 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 */
$c->setId(“”);
$c->setName($pharmacySeqNo);
/* These below are the column name which set the content for the relevant column name */
$c->setContentTitle($content);
/* The ContentDescription is column name which is CONTENT_DESCRIPTION*/
$c->setContentDescription($desc);
$c->setInsertedDate(date(‘d-m-Y’));
$c->setInsertedBy($userId);
$c->setStatus(‘A’);
$c->save();
/*Finally we have to set the object to save function it will run the query with above relevent fields */

Sep.04

How to paginate the symfony list data

pagination_on_symfony

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();
//$c->add(ClkPerPackageTypePeer::STATUS,’1′);
$pager->setPage($this->getRequestParameter(‘page’, 1));
$pager->setCriteria($c);
$pager->init();
$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>
</tr>
<?php
$page_counter++;
endforeach;

 

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; ?>
</div>

pagination_on_symfony

 

 

Sep.02

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.

$this->redirect($this->generateUrl(‘sf_guard_signin’));

and

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

 

Sep.02

How to add Style and Javascript pages on Symfony

Config_file_for_Scripts

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

Config/view.yml

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]