Symfony Helpful Query


Select all not null column from the TblCms Table. The criteria ISNOTNULL is used to get not empty column from the table.

$cri = new Criteria();
$cri->add(TblCmsPeer::id, $c->getId());
$cri->add(TblCmsPeer::insertedBy,  NULL,Criteria::ISNOTNULL);
$this->selOne = TblCmsPeer::doSelectOne($cri);


Here $myId is the variable which compares the value with table value and This query should return the expect this id rows of data.

$cri = new Criteria();

$cri->add(TblCmsPeer::id, $c->getId());
$cri->add(TblCmsPeer::insertedBy, $myId,Criteria::NOT_EQUAL);
$this->selOne = TblCmsPeer::doSelectOne($cri);


This will search $search_title = “welcome nepal” from the database column.

$cri = new Criteria();

$cri->add(TblCmsPeer::id, $c->getId());
$this->selOne = TblCmsPeer::doSelectOne($cri);

Or Condition in Query Symfony: 

$c = new Criteria();
$c->add(ForwardedPharmacyDeletedLogPeer::CURRENTLY, ‘1’);
$cc = $c->getNewCriterion(ForwardedPharmacyDeletedLogPeer::FORWARDED_TO,$userId);
$c2 = $c->getNewCriterion(ForwardedPharmacyDeletedLogPeer::REVERTED_TO,$userId);
$my_assigned_pharmacy_list = ForwardedPharmacyDeletedLogPeer::doSelect($c);

Or Condition resultOr_query


More Criterias :

EQUAL Comparison type.
NOT_EQUAL Comparison type.
ALT_NOT_EQUAL Comparison type.
GREATER_THAN Comparison type.
LESS_THAN Comparison type.
GREATER_EQUAL Comparison type.
LESS_EQUAL Comparison type.
LIKE Comparison type.
NOT_LIKE Comparison type.
CONTAINS_ALL Comparison for array column types
CONTAINS_SOME Comparison for array column types
CONTAINS_NONE Comparison for array column types
ILIKE PostgreSQL comparison type
NOT_ILIKE PostgreSQL comparison type
CUSTOM Comparison type.
CUSTOM_EQUAL Comparison type for update
DISTINCT Comparison type.
IN Comparison type.
NOT_IN Comparison type.
ALL Comparison type.
JOIN Comparison type.
BINARY_AND Binary math operator: AND
BINARY_OR Binary math operator: OR
ASC “Order by” qualifier – ascending
DESC “Order by” qualifier – descending
ISNULL “IS NULL” null comparison
ISNOTNULL “IS NOT NULL” null comparison
LOGICAL_OR logical OR operator
LOGICAL_AND logical AND operator




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]


Setting up Symfony Project on windows

Hi guise i Have share my experience to you when What i have got when setting up symfony project on my computer.

I have share the steps require to install symfony project.

I have created the project folder name pkb and url : pkb.localhost

Step 1: At first we need to create development environment
[Which is located in C:\WINDOWS/system32/drivers/etc/hosts ] Open this file and add the virtual host mapping with localhost ip.
#hosts file pkb.localhost
# add the localhost ip( with virtual domain (pkb.localhost). [pkb.localhost] is virtual host now

Step 2:
Need to add the virtual host mapping with project name.
Which is located into Wamp server [Apache/ httpd.conf].
Local location where the wamp version 2.2 have installed into D:
So the absolute location : D:\wamp\bin\apache\apache2.2.22\conf\httpd.conf
Edit File (and add the virtual host mapping with project)
# httpd.conf

ServerName pkb.localhost
DocumentRoot “D:\development\sfprojects\pkb\web”
DirectoryIndex index.php
<Directory “D:\development\sfprojects\pkb\web”>
AllowOverride All
Allow from All

Alias /sf D:\development\sfprojects\pkb\lib\vendor\symfony\data\web\sf
<Directory “D:\development\sfprojects\pkb\lib\vendor\symfony\data\web\sf”>
AllowOverride All
Allow from All
Step 3:
Create project folder with {Drive or D:/}development/sfproject/{project_name}/lib/vendor
Now in this example:
(Create below folder structure)

After creating folder structure for symphony project installation we need the symphony version and place this symphony version folder content with making sure of folder name symphony.
For download latest stable version of Symfony. Go through this link http://symfony.com/download.
Now we find the symphony project [we have multiple files and folders in symphony downloaded folder.] D:\development\sfprojects\pkb\lib\vendor\symfony\

[Put the downloaded symfony project under vendor folder]


Step 4:
After putting symphony project into lib/version
We need to help from command line for generating default project files and folder.
Go to project installed folder by command line.
Run >> cmd
Go to place of project root folder {pkb} for this example.
\data\bin\symfony generate:project test –orm=Propel


[It generates the project default file and folder structure.] Step 5:
For generate the application the application have modules,configuration,libraryfiles and template files.
Below syntax creates the frontend application with its folder structure.
D:\Development\sfprojects\pkb>php symfony generate:app frontend


Step 6:(Database Connection)
Create database from the php myadmin connect it from the application.
[below is the connection of database pkb_symfony with mysql user name root with blank password(If we have password of mysql we need to put it after root with space like root password )] D:\Development\sfprojects\pkb>php symfony configure:database “mysql:host=localhost;
dbname=pkb_symfony” root
(It creates the connection file of database pkb_symfony with symphony project it is located in
D:\development\sfprojects\pkb\config\databases.yml File)

Step 7: (Generating schema,model and forms)
Symfony generates all the schema file [The yml file which have all table structure and data types of this database with yml structure.], model [The connection between the controller(action) database query supportive function will automatically generated. ] and forms (all the default forms which helps to generate form of the table.) file.
We need to run the command to generate these all
Schema Files
Model Files
And Forms file
Command >

1. D:\development\sfprojects\pkb>php symfony propel:build-schema

2. D:\Development\sfprojects\pkb>php symfony propel:build-model
3. D:\Development\sfprojects\pkb>php symfony propel:build-froms


Download Word File