How to use constant variables in Yii


Posted on 16 Apr 15 by Vickey

In Yii we can define our constant in /config/params.php file

return [
    'adminEmail'        => '',
    'application_name'  => 'My App',

and in our views an controller we can access these by using

Yii::app()->params['application_name'];  // in yii 1

Yii::$app->params['application_name']; // in yii 2

How to use constant variables in Laravel


Posted on 16 Apr 15 by Vickey

Some times we need to show same text at more then one pages or places in a website so we need a global variable or constant for doing this. If we want to change that text then we can change it from only one place where we defined it. We can do this in laravel very easily

Create a file constants.php under app/config directory


Now add

return [
    'APP_NAME' => 'My App'

you can add your constant like this

and now you can access it in your views and controllers

echo Config::get('constants.APP_NAME');

output will be My App

Change tar.gz, tgz packege to deb format in ubuntu

Ubuntu Desktop

Posted on 16 Apr 15 by Vickey

For convert packege to deb we need to install alien so lets first install alien

sudo apt-get install alien

this command will install alien when alien will installed run command

sudo alien --to-deb ~/Desktop/yourpackege.tgz

if your packege is on Desktop otherwise give your packege full path and you can find your deb packege on you home folder. Now by right clicking on deb packege open it with Ubuntu software center and it will be installed in your system

How to get days difference between two given dates in php


Posted on 15 Apr 15 by Vickey

Calculate days, months and years difference between two given date

function getDayDifference($time1, $time2, $accuracy = 6) {
        if (!is_int($time1)) {
            $time1 = strtotime($time1);
        if (!is_int($time2)) {
            $time2 = strtotime($time2);

        if ($time1 > $time2) {
            $t_time = $time1;
            $time1 = $time2;
            $time2 = $t_time;
        $timeinterval = array('year','month','day','hour','minute','second');
        $differents = array();
        foreach ($timeinterval as $interval) {
            $t_time = strtotime('+1 ' . $interval, $time1);
            $counter_add = 1;
            $looped = 0;
            while ($time2 >= $t_time) {
                $t_time = strtotime("+" . $counter_add . " " . $interval, $time1);
            $time1 = strtotime("+" . $looped . " " . $interval, $time1);
            $differents[$interval] = $looped;
        $count = 0;
        $times = array();
        foreach ($differents as $interval => $value) {
            if($count >= $accuracy) {

            if ($value > 0) {
                if ($value != 1) {
                    $interval .= "s";
                $times[] = $value . " " . $interval;
        return implode(", ", $times);

    echo getDayDifference($time1,$time2);


Set default timezone in cakephp


Posted on 15 Apr 15 by Vickey

For change defualt timezone open your core.php and add code

Configure::write('TimeZone', 'America/New_York');

How to get elapsed time from a given date in php


Posted on 14 Apr 15 by Vickey

By using the below code we can get elapsed or expired time in readable form for example 1 hour ago, 10 Second ago etc

function elapsedTime($date)
     if(empty($date)) { 
         return "No date provided"; 
     $periods_type = array("second", "minute", "hour", "day", "week", "month", "year", "decade"); 
     $lengths = array("60","60","24","7","4.35","12","10"); $now = time(); 
     $unixdate = strtotime($date); 

     if(empty($unixdate)) { 

         return "Bad date"; 
     if($now > $unixdate) { 

         $get_difference = $now - $unixdate; $tense = "ago"; 

     } else { 

         $get_difference = $unixdate - $now; $tense = "from now"; 
     for($j = 0; $get_difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {

     $get_difference /= $lengths[$j]; } $get_difference = round($get_difference); 

     if($get_difference != 1) { 

         $periods_type[$j].= "s"; 
     return "$get_difference $periods_type[$j] {$tense}"; 
 echo elapsedTime('15-04-14 12:38:25');


How to use secure paypal form


Posted on 14 Apr 15 by Vickey

Simple paypal form is not secure in a web application. it can easily changed by any one who have some tecnical skill user can change amount or other details in the form. so there is need to hide the form. In the below script a paypal form will genereate when user click on pay now button. The use can not change any details of this form.

<?php if(isset($_POST['paypalSubmit'])) { ?>
    <form action="<?php echo PAYPAL_URL ?>" method="post" id="paypalForm"> 
    <input type="hidden" name="cmd" value="_cart"> 
    <input type="hidden" name="upload" value="1">
    <input type="hidden" name="business" value="PAYPAL_ACCOUNT">
    <input type="hidden" name="return" value=""> 
    <input type="hidden" name="notify_url" value="">
    <input type="hidden" name="cancel_return" value="">

    <input type="hidden" name="item_number_1" value="">
    <input type="hidden" name="item_name_A" value="">
    <input type="hidden" name="amount_1" value="">

    <input type="hidden" name="item_number_2" value="">
    <input type="hidden" name="item_name_B" value="">
    <input type="hidden" name="amount_2" value="">

    <input type="hidden" name="cpp_logo_image" value="paypal_logo.png">
    <input type="hidden" name="cpp_headerback_color" value="#CCC">    
    <input type="hidden" name="cpp_headerborder_color" value="#CCC">    
    <script type="text/javascript">
<?php  } ?>

<form method="post">
  <input type="submit" name="paypalSubmit" border="0" id="paypal" value=""> 

Create and remove elements or text fields by dom in javascript


Posted on 13 Apr 15 by Vickey

Here i am using dom for create and remove elements. I have a div and a button on this page by clicking button i will add or create new text field and a button for remove the field first got the existing div by id. now create a new div and a button for reomve the text fields after this append input fields and button in new created div and finally append new div in parent div

<div id="parentDiv"></div>
<input type="button" onclick="addmore();" value="Add text field">

function addmore(){
    var parentElement=document.getElementById('parentDiv');
    var newDiv=document.createElement('div');
    var input_fields=document.createElement('input');

    var newButton=document.createElement('input');
    newButton.className = "removeButton";
    newButton.title='Remove Your Choice.';'pointer';
    newButton.onclick=function RemoveEntry()

How to give read write permission to a directory in ubuntu (linux)

Ubuntu Desktop

Posted on 11 Apr 15 by Vickey

If i have a directory myprojects under /var/www then there are two ways to give read write permission

open terminal by pressing Ctrl+Alt T when terminal window open type

cd /var/www


sudo chmod -R 0777 myprojects

press enter

or type in terminal

sudo chmod -R 0777 /var/www/myprojects

How to add pie chart ( high chart ) on a webpage


Posted on 09 Apr 15 by Vickey
<script src="/js/jquery.min.js"></script>
<script src="/js/highcharts.js"></script>
$(function () {

        legend: {
            itemMarginTop: 10,
            itemMarginBottom: 10,
            borderWidth: 0,
            itemDistance: 45,
            backgroundColor: '#FCFFC5'
        chart: {
            plotBackgroundColor: '#f7f7f7',
            plotBorderWidth: null,
            plotShadow: false,
            borderColor: 'red',
            borderWidth: 0,
            plotShadow: false,
            shadow: false,
            backgroundColor: '#f7f7f7',
            plotBackgroundImage: 'imageurl'
        colors: ['#69d2e7', '#f48631', '#e0e4cd', '#7d4f6c', '#47bfbd','#8c8c8c'],
        exporting: { enabled: false },
        title: {
            text: 'Test'

        tooltip: {
            pointFormat: '{}: <b>{point.percentage:.1f}%</b>'

        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: false

                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    format: '<b>{}</b>: {point.percentage:.1f} %'
                 showInLegend: true
        series: [{
            type: 'pie',
            name: 'Movement Summary',
            innerSize: '50%',
            data: [

            ['Jan',    8.5],
            ['Feb',     6.2],
            ['Mar',   0.7]
<div id="container" style="height: 400px"></div>