Friday 30 December 2011

How to add Google Map on your page?

 Hi Guys!

Plesae put following lines on your page to add google map:



<!DOCTYPE html>
<html>
  <head>
    <title>Google Maps JavaScript API v3 Example: Map Simple</title>
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta charset="UTF-8">
    <style type="text/css">
      html, body, #map_canvas {
        margin: 0;
        padding: 0;
    width: 400px;
        height: 400px;
      }
    </style>
    <script type="text/javascript"
        src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>

    <script type="text/javascript">
      var map;
      function initialize() {
        var myOptions = {
          zoom: 18,
          center: new google.maps.LatLng(-34.397, 150.644),
          mapTypeId: google.maps.MapTypeId.TERRAIN
        };
        map = new google.maps.Map(document.getElementById('map_canvas'),
            myOptions);
      }

      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <div id="map_canvas"></div>
  </body>
</html>

Cheers!

Monday 19 December 2011

How to send array from action to template in symfony?


Suppose we have testArray given following:

$this->testArray = array('ashwani', 'bablu','cintu');
$myArray = $sf_data->getRaw('testArray');
print_r($myArray);

Output will be in template file:

Array
(
    [0] => 'ashwani'
    [1] => 'bablu'
    [3] => 'chintu'
)


Cheers!

Thursday 15 December 2011

How to generate Module in symfony?

$ php symfony doctrine:generate-module frontend organizer EventOrganizer

this will generate template with tr td format.

OR

$ php symfony doctrine:generate-module  --with-show --non-verbose-templates frontend organizer EventOrganizer

this will generate template with echo $form format.




here organizer is a module name and EventOrganizer is table name defined in schema.yml


Cheers!

Thursday 13 October 2011

How to find text recursively in file using linux commad?

Folks,

Please use the following command:

find <folderpath> -type f | xargs grep -l "131848637983654"

Here "131848637983654" has to find in <folderpath>

Cheers!

Monday 3 October 2011

How to use symfony inbuild functions in non-symfony class in lib folder?

Dear,

$sfUser = sfContext::getInstance()->getUser();
$sfRequest = sfContext::getInstance()->getRequest();
$sfController = sfContext::getInstance()->getController();

$sfUser->setAttribute('abc','yes');
$sfRequest->setMethod();
$sfController->redirct('cart/list');


Cheers!

Thursday 29 September 2011

How to automatically backup mysql database using cron?

Hi All,

Open crontab in linux server or window server and write the following line. this will backup database each mint.

$crontab -e

press enter and crontab will be opened and write following line:

* * * * * mysqldump -uroot -proot  ipay4me | gzip -9 > /var/www/archive/dbbackup/ipay4me.sql.gz


OR


$vim /var/www/archive/dumpdatabase

Write down following lines into that file:

#!/bin/bash
clear
mysqldump -uroot -hlocalhost -proot ipay4me | gzip -9 > /var/www/archive/dbbackup/ipay4me_$(date +"%d-%m-%Y-%H-%I-%S").sql.gz
exit 0


Set crontab:

50 11 * * * /var/www/archive/dumpdatabase /usr/bin/php Asia/Calcutta >/dev/null 2>&1

This cron will run daily at 11:50 PM



Cheers!

Tuesday 27 September 2011

How to import a compressed mysql file .sql.gz using linux?

Hellos,

Please do the following to do the same.

zcat /newsites/urdutahzeeb/urdutahzeeb.net/dbbackup/urdujoom.sql.gz | mysql -u naughty -p urdujoom

Cheers!


Wednesday 21 September 2011

How to change color on focus of input box using jquery?

Hi Dear,

<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
.focused {
    background: #abcdef;
}
</style>
<form name="focusForm" id="focusForm" method="POST" >
<table width="100%" cellspacing="2" cellpadding="2" >
    <tr>
        <td width="180">First Name: </td>
        <td><input type="text" name="txtFName" value="" /></td>
    </tr>
    <tr>
        <td>Last Name: </td>
        <td><input type="text" name="txtLName" value="" /></td>
    </tr>
    <tr>
        <td>Age: </td>
        <td><input type="text" name="txtAge" value="" /></td>
    </tr>
    <tr>
        <td>Occupation: </td>
        <td><input type="text" name="txtOccupation" value="" /></td>
    </tr>
    <tr>
        <td>Secret Question: </td>
        <td><input type="text" name="txtQuestion" value="" /></td>
    </tr>
    <tr>
        <td>Answer: </td>
        <td><input type="text" name="txtAnswer" value="" /></td>
    </tr>
</table>
</form>
<script>
//$("#focusForm input:first").focus();
//$("#focusForm :input").attr('disabled','disabled');
$("#focusForm :input").live("focus blur", function(e) {
    var el = $(this);
    el.toggleClass("focused", el.is(":focus"));
});
</script>

Cheers!

Tuesday 20 September 2011

How to check all checkbox using jquery?

Hi Guys!

include jquery.js on the top of file and then write following code:

<form name="frm" id="frm" >
<input type="checkbox" name="abc[]" id="1" value="1" >Yes
<input type="checkbox" name="abc[]" id="2" value="2" >No
<input type="checkbox" name="abc[]" id="3" value="3" >None
<input type="button" name="btnCheckAll" value="Check All" onclick="checkAll();" />
</form>
<script>
function checkAll(){
$("#frm input[@name='abc'][type='checkbox']").attr('checked', true);
}

Cheers!

Tuesday 2 August 2011

How to block mouse right click using javascript?

Guys,

Do the following to block right click:

<script>
$(document).ready(function()
    {
          $(document).bind("contextmenu",function(e){
                  return false;
          });
    });
</script>

Cheers!

Friday 29 July 2011

How to delete duplicate record in mysql?

Hi Folks,

Suppose we have a table name employee consisting two fields:

Table Name: employee
id  name
1   ashwani
2   varun
3   rajesh
4   varun
5   amit
6  ashwani


CREATE TABLE new_employee as SELECT * FROM employee WHERE 1 GROUP BY name;

DROP TABLE employee;

RENAME TABLE new_employee TO employee;


Cheers!

How to enable error log in php?

Hi Folks,

Go to vim etc/php5/apache2/php.ini where you will find log_errors = Off

change Off to On. save file and exit.

Now restart apache server with the following line:

sudo etc/init.d/apache2 restart

Now,

To see what is coming into log, do the following task:

create php file and wirte some code with errors.

and run the following command:
tail -f var/log/apache2/error.log


Cheers!

Wednesday 20 July 2011

How to get 2nd highest salary in mysql?

HI Guys,

There are two way to get solution:

1.) select distinct(salary) from employee order by salary desc limit 1,1 ;
2.) select max(salary) from employee where salary < (select max(salary) from employee);

Thanks

Cheers!

Monday 18 July 2011

How to dump database using linux command?

Hellos,

Suppose

host = localhost
user = root
password = root
database = payforme

Then

Type the following command:
$ mkdir mysqldumpfolder;
$ cd mysqldumpfolder;
mysqldumpfolder $ mysqldump -u root  -h localhost -p  payforme | gzip -9 > payforme.sql.gz;

After enter it will ask you to enter password.
give mysql password and mysql start dumping your database to mysqldumpfolder folder.

Friday 15 July 2011

How to get all form error in symfony?

Hi Guys,

1. First Method:

Add following line in the template:

foreach($form->getWidgetSchema()->getPositions() as $widgetName)
{
  echo $widgetName." == ".$form[$widgetName]->renderError();
  echo "<br />";
}

Using above script, you will find something like this:

first_name == Please enter First Name.
last_name == Please enter Last Name.
address1 == Please enter Address 1.

2. Second Method:

 public function getAllErrors()
  {
       $err = array();
       foreach ($this as $form_field){
         if ($form_field->hasError()){
           $err_obj = $form_field->getError();
           if ($$err_obj instanceof sfValidatorErrorSchema){
             foreach ($err_obj->getErrors() as $err){
               $err[$form_field->getName()] = $err->getMessage();
             }
           }else{
             $err[$form_field->getName()] = $err_obj->getMessage();
           }
         }
       }
       // global err
       foreach ($this->getGlobalErrors() as $validator_err){
         $err[] = $validator_err->getMessage();
       }
       return $err;
  }

put above function in your form class. and call this function in your action.class.php as given below:

$this->form->getAllErrors();

Using above method, you will get something like this:

Array
(
    [first_name] => Please enter First Name.
    [last_name] => Please enter Last Name.
    [address1] => Please enter Address 1.
    [town] => Please enter Town.
    [country] => Please select Country
    [email] => Please enter E-Mail address
    [phone] => Please enter Phone Number
    [address_proof] => Please upload credit card statement.
    [user_id_proof] => Please upload identity proof.
    [card_Num] => Please enter Card Number
    [card_holder] => Please enter Card Holder name.
    [transaction_type] => Please select transaction type.
)


Cheers!

Tuesday 28 June 2011

How to check where our database files located in linux?

Go to mysql using command line.

> mysql -u root -p
mysql> SHOW VARIABLES LIKE 'datadir';
+---------------+-----------------+
| Variable_name | Value           |
+---------------+-----------------+
| datadir       | /var/lib/mysql/ |
+---------------+-----------------+

Now

exit from mysql and do the follwoing

> cd /var/lib/mysql

Here you will see all the database exist in this folder.

Cheers!

Wednesday 11 May 2011

How to get difference between two folder using linux command?

Hi

Use the following syntax to get difference b/w folders:

 diff  /home/ashwanik/public_www/openid_old /home/ashwanik/public_www/openid_new  |sort


To check recursively go down subdirectories, add -r.

diff -qr <first folder> <second folder>  |sort


Cheers!

Tuesday 10 May 2011

How to create error pages in symfony?

Hi Guys,

Symfony provides following error pages:
1.) indexSuccess.php
2.) error404Success.php
3.) loginSuccess.php
4.) secureSuccess.php
5.) disabledSuccess.php
6.) unavailableSuccess.php

The above files you can find on your project. Below is the location of files;

 /var/www/project-folder/lib/vendor/symfony/lib/controller/

in controller folder, you will find a "default" module.

so all success files are located in default/templates/

Either change files here OR copy "default" module and paste it into your apps/frontend/modules/


There are two another pages which also need to be customized. you will find these default pages in the symfony_data_dir/web/errors/ directory:

    1) error500.php: Page called when an internal server error occurs.
    2) unavailable.php: Page called when a user requests a page while the cache is being cleared.

To customize these pages, create error500.php and unavailable.php pages in your application's web/errors/ directory.  Symfony will use these instead of its own.



Cheers!

Saturday 30 April 2011

How to setup symfony project?

Hey Fox,

Download symfony project.
create folder let suppose symfony_test i.e, mkdir symfony_test
Go into symfony_test and create lib folder i.e, c:\>symfony_test> mkdir lib
Go into lib folder and create vendor folder ie., c:\>symfony_test\lib\> mkdir vendor

Now,

extract symfony project into vendor folder.

Further, open command prompt and type the following
c:\> cd wamp\www\symfony_test
c:\wamp\www\symfony_test> php lib\vendor\symfony\data\bin\symfony generate:project jobeet
c:\wamp\www\symfony_test> php symfony configure:database "mysql:host=localhost;dbname=jobeet" root root
c:\wamp\www\symfony_test> symfony generate:app --escaping-strategy=on --csrf-secret=UniqueSecret frontend


OR



Now, create the frontend application by running the generate:app task:
$ php symfony generate:app frontend




create model, form and filter on the basis of schema.yml and then

I am going to create a module "job" on the basis of model "JobeetJob"

c:\wamp\www\symfony_test> php symfony doctrine:generate-module --with-show --non-verbose-templates frontend job JobeetJob


Cheers!



How to run symfony on dos prompt?

Hey,

To run symfony in windows machine, you just set the Environment Vairables if not set for php.

Following are the steps to set Environment Variables on window machine:

Right click on MY Computer
Go to properties
Choose the Advanced tab
Click Environment Variables
Now you can edit the environment variables of the system.
In this window, you will see User Variables and System Variables.
If you change in User Varibale then changes will be applicable for your login only.
If you change in System Variable then changes will be applicable for all users.
So,
find "PATH" variable in the list of system variables.
Select it and press edit button given below.

Let Suppose, this example using wamp and wamp installed in D: drive.

now,

append the following line in variable value fields:
D:\wamp\bin\php\php5.2.8\

this folder conatains php.exe file.

now press OK and save the configuration.

Futher, the most important point. Restart your machine.


Note the ; character. It is used to separate directories in the variables, so be sure it is present.

Again, D:\path\to\php is where your php.exe is located.

Cheers!

Wednesday 27 April 2011

How to read last 10 line in a file using linux command?

tail -10 filename

also,

tail -f filename

Cheers!

How to go start and end of the file open fron VI?

For Beginning press esc then :0
For Ending press esc :$ OR shift+g

Cheers!

Tuesday 26 April 2011

How to put error message below the field in symfony form?

Hey,

Got to /lib/form/doctrine/BaseFormDoctrine.class.php
adn put following line in public function setup().
$row_format   = "<tr>\n<th>%label%</th>\n<td>%help%%field%%error%%hidden_fields%</td>\n</tr>\n";
$this->getWidgetSchema()->getFormFormatter()->setRowFormat($row_format);

see example below:


## /lib/form/doctrine/BaseFormDoctrine.class.php
<?php

/**
 * Project form base class.
 *
 * @package    passportServices
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormBaseTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
abstract class BaseFormDoctrine extends sfFormDoctrine
{
  public function setup()
  {     
    $row_format   = "<tr>\n<th>%label%</th>\n<td>%help%%field%%error%%hidden_fields%</td>\n</tr>\n";
    $this->getWidgetSchema()->getFormFormatter()->setRowFormat($row_format);     
  }
}

Cheers!

How to remove .svn folder using linux command?

Go to that folder and run the following command:

find ./ -name ".svn" | xargs rm -Rf


Cheers!

Thursday 27 January 2011

How to remove ^M from VI editor ?

Hellos


To remove this, open your file in vi editor and type
:%s/(ctrl-v)(ctrl-m)//g

OR

:%s/^M//g


Here %s is search and replace command in VI
^M is need to replace
Enter text between // which you want there
and 
finally g is using for all occurrences.




Cheers!

Friday 21 January 2011

How to run php commands in command line on ubuntu?

Use the following example to run php command in command line:

$ php -a
php > echo 'aswani kumar';
ashwani kumar
php >


Cheers!

Friday 7 January 2011

How to copy files/folder in ubuntu/putty?

Hi

Suppose you have a folder which name is ashwani & it contains some content and now you want to create new folder name kumar with same content.

So

source = ashwani
destination = kumar

cp -r <source> <destination>

Note: -r is being used for subfolder and files.

Cheers!