Search This Blog

Thursday, December 16, 2010

How to download files in Symfony

Its very easy to download files in symfony. Create a proper action and do something like this , i have assumes that files are stored in the database and its a pdf file. But you can assign any file by storing the file type in the database.



public function  executeDownloadFile(sfWebRequest $request) {
        $yourfileData = '' // get your file data from the database
        $this->getResponse()->clearHttpHeaders();
        $this->getResponse()->setHttpHeader('Content-Disposition',
        'attachment; filename='. 'myfile.pdf');
        $this->getResponse()->setContentType('application/pdf');
        $this->getResponse()->sendHttpHeaders();       
        $this->getResponse()->setContent($yourfileData);

        return sfView::NONE;

}

If you need to set http headers 

private function setHttpHeaders($size, $fileName, $contentType='application/csv') {
        $this->getResponse()->clearHttpHeaders();
        $this->getResponse()->addCacheControlHttpHeader('Cache-control', 'private');
        $this->getResponse()->setHttpHeader('Content-Description', 'File Transfer');
        $this->getResponse()->setContentType($contentType, TRUE);
        $this->getResponse()->setHttpHeader('Content-Length', (string) $size, TRUE);
        $this->getResponse()->setHttpHeader('content-transfer-encoding', 'binary', TRUE);
        $this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename=' . $fileName, TRUE);
        $this->getResponse()->sendHttpHeaders();
    }

Tuesday, December 14, 2010

Recursively deletes subversion .svn folders in ubuntu

First we find the .svn folders, then we use rm to remove those folders . There are 2 methods to do this.Type this in shell


Method -1

$ find . -name ".svn" -exec rm -rf {} \;
Method -2

$ rm -rf `find . -type d -name .svn`

Sunday, December 5, 2010

Save new record or Update a record if it exist using Doctrine object

Are getting error when you save a doctrine object saying primary key violation?
Before you save the object you must search if its already there. When you use find it uses the primary key.

public function saveFamilyDetails($form) {

$employeeFamilyDetails = Doctrine::getTable('EmployeeFamilyDetails')->find($form['txtFamilyID']);

        if(!($employeeFamilyDetails instanceof EmployeeFamilyDetails) ) {
            $employeeFamilyDetails = new EmployeeFamilyDetails();
        }

        $employeeFamilyDetails->employee_id       = $form['txtEmpID'];
        $employeeFamilyDetails->fm_name       = $form['txtFamName'];
        $employeeFamilyDetails->relationship       = $form['txtFamRelationship'];
        $employeeFamilyDetails->date_of_birth        = $form['txtFamDob'];
        $employeeFamilyDetails->address        = $form['txtFamAddress'];
        $employeeFamilyDetails->mobile_no      = $form['txtFamMobileNo'];
        $employeeFamilyDetails->residence_no    = $form['txtFamRecidenNo'];
        $employeeFamilyDetails->workcon_no   = $form['txtFamWorkConNo'] ;
        $employeeFamilyDetails->dependent      = $form['txtFamDependant'];
        $employeeFamilyDetails->nric_fin    = $form['txtFamNricFin'] ;
        $employeeFamilyDetails->passpot_no   = $form['txtFamPassport'] ;

        return $employeeFamilyDetails->save();



    }

Monday, November 15, 2010

How to make word wrap in HTML table

td{
max-width: 200px; 
word-wrap: break-word;
}

Friday, November 12, 2010

Some useful symfony commands

These are some useful symfony commands


Create a symfony module

php symfony generate:module orsss  mymodule


Create symfony schema from the database

php symfony doctrine:build-schema

build models

php symfony doctrine:build-model

insert the created sql

php symfony doctrine:insert-sql

list all the back end routes

php symfony app:routes backend

publish assets of a plugin to web directory

php symfony plugin:publish-assets

create a sfGuard user

symfony guard:create-user indrakeerthi@gmail.com admin admin poojitha jayasinghe

build everything from scratch

symfony doctrine:build --all --and-load --no-confirmation

Monday, November 8, 2010

How to Uninstall Netbeans

root@user:/usr/local/netbeans-6.9# ./uninstall.sh

Tuesday, November 2, 2010

Find the last day of the given month in PHP

function getLastDayOfMonth($year,$month) {
    $lastdayOfMonth = date('Y-m-d',strtotime('-1 second',strtotime('+1
                  month',strtotime($month.'/01/'.$year.' 00:00:00'))));

    return $lastdayOfMonth;
}



This function gets current month and year as the input returns the last day of the month.

It add one month to the current month and reduce one second from the 00:00:00 th hour of the first day so to get the last day of this month.

Wednesday, October 27, 2010

Steps to install a plugin in Symfony

Listing 17-15 - Installing a Plug-In from the Symfony Wiki
> cd myproject
> php symfony plugin-install http://plugins.symfony-project.com/pluginName
> php symfony cc


Listing 17-16 - Installing a Plug-In from a Downloaded PEAR Package
> cd myproject
> php symfony plugin-install /home/path/to/downloads/pluginName.tgz
> php symfony cc


Listing 17-17 - Installing a Plug-In from a PEAR Channel
> cd myproject
> php symfony plugin-install channelName/pluginName
> php symfony cc


Don't forget to enable the plugin in ProjectConfiguration.class.php
$this->enablePlugins('sfTaskExtraPlugin')

read more

Ubuntu command to get the System hardware configurations

Run this command as the super user to get the complete hardware configurations
>lshw

Tuesday, October 26, 2010

How to run a single PHP Unit Test

How to run a single PHP Unit Test

phpunit --filter EmpSalaryReportTest AllTests.php

// Get unit test coverage report

phpunit --coverage-html ./report BankAccountTest

phpunit --coverage-html AllTests AllTests.php

Sunday, October 24, 2010

How to change MySQL admin password

mysqladmin -u root -p 'oldpassword' password newpass

MySQL case sensitivity of table names

When you transport databases from Linux to windows you may encounter errors due to table names being in uppercase . This happens because windows is case sensitive. You can override this problem by adding this parameter to your my.ini file.

lower_case_table_names=0


more on mysql site

Thursday, October 21, 2010

How to import project to SVN

This is useful if you want to move a copy of existing svn
directory to another svn directory
$ svn import -m "Adding the new file" 
              ourProject http://yourserver/repos/

Friday, October 15, 2010

How to create a new svn project and upload files

First create a new directory by issuing this command in the terminal
>svn mkdir -m "message" 
http://svnserver.com/repos/abc

now go to your working directory

abc>svn import -m "message" 
http://svnserver.com/repos/abc 
-m  has the comment you can write anything inside

Install Bisigi theam in ubuntu

sudo add-apt-repository ppa:bisigi/ppa && sudo apt-get update

sudo apt-get install bisigi-themes

Thursday, October 14, 2010

How to restore accidentally deleted crontab file

If you have accidentally deleted crontab file, probably using -r instead of -e. It happens because the keys are at the same place :-) , this is could be the rescue. Try to find the file inside Tmp folder.

go to /tmp

ls -ltr cron*

This will show a history of files. Choose the most reason one.

Monday, October 11, 2010

Command to list the disk partitions in Ubuntu

Command to list the disk partitions in Ubuntu . Login as the admin type this in command line

>fdisk -l

Thursday, October 7, 2010

Find an element Id which match a pattern in jquery

Using jquery its possible to find an element that matches a specific pattern. This code will find each input Id and check if its greater than 24

           $("input[id^=duration_]").each(function() {

                if($(this).val()>24){
                    alert('Duration should be less than 24');
                     returnValue = false;
                }

            });
more examples 

Tuesday, October 5, 2010

How to find the history of the commands given in Ubuntu

Type this command in the ubuntu console

>history

If you need a specific set of commands

>history|grep svn

How to revert svn repository to previous version number

svn merge -rHEAD:4130 .

How to svn check out from a specific revision number

svn co -r REVISION SOURCE 

How to rename svn repository

If you want to rename a svn repository you can use either of these commands

svn move SOURCE DESTINATION
svn rename SOURCE DESTINATION