Modify your CActiveDataProvider in Yii Framework

This is very useful things who are using Widget

  1. $dataProvider=new CActiveDataProvider(‘Post’, array(
  2.     ‘criteria’=>array(
  3.         ‘condition’=>‘status=1′,
  4.         ‘order’=>‘create_time DESC’,
  5.         ‘with’=>array(‘author’),
  6.     ),
  7.     ‘pagination’=>array(
  8.         ‘pageSize’=>20,
  9.     ),
  10. ));

 

 

JavaScript split() Method

  1. <script type=“text/javascript”>
  2.  
  3. var str=“How are you doing today?”;
  4.  
  5. document.write(str.split() + “<br />”);
  6. document.write(str.split(“ ”) + “<br />”);
  7. document.write(str.split(“”) + “<br />”);
  8. document.write(str.split(“ ”,3));
  9.  
  10. </script>

The output of the code above will be:

How are you doing today?
How,are,you,doing,today?
H,o,w, ,a,r,e, ,y,o,u, ,d,o,i,n,g, ,t,o,d,a,y,?
How,are,you

.remove() in jQuery API

.remove() is a function in jquery for remove anything is right process.

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <style>{ background:yellow; margin:6px 0; }</style>
  5.   <script src=“http://code.jquery.com/jquery-latest.js”></script>
  6. </head>
  7. <body>
  8.   <p>Hello</p> 
  9.   how are 
  10.   <p>you?</p>
  11.   <button>Call remove() on paragraphs</button>
  12. <script>
  13.     $(“button”).click(function () {
  14.       $(“p”).remove();
  15.     });
  16.  
  17. </script>
  18.  
  19. </body>
  20. </html>

 

Check which check box is checked in simple jquery with html form

This is very easy example to find out which check box is checked.

You can copy and paste it for test.

Careful You need to internet connection for test that. Because “jquery-1.7.min.js” file browse from internet.

Rajib Kumar Rakhmit

Web Developler

  1. <!DOCTYPE html PUBLIC ”-//W3C//DTD XHTML 1.0 Transitional//EN” ”http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
  2. <html xmlns=“http://www.w3.org/1999/xhtml”>
  3. <head>
  4. <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8″ />
  5. <title>CheckBox Check in Jquery</title>
  6. </head>
  7.  
  8. <body>
  9. <script src=“http://code.jquery.com/jquery-1.7.min.js” type=“text/javascript”></script>
  10. <div style=display: block; width: 780px; id=“message_inbox” class=“page-mid”>
  11.     <div style=margin-top:10px;>
  12.     <input type=“button” title=“Delete selected emails [Delete]“ value=“Delete” id=“delete” name=“”>
  13.     <input type=“button” title=“Reply to sender” value=“Reply” id=“reply_sender” name=“”>
  14.     <input type=“button” title=“Reply to all” value=“Reply All” id=“reply_all” name=“”>
  15.     <input type=“button” title=“Forward this mail” value=“Forward” id=“forward” name=“”>
  16.     </div>
  17. <form id=“messageBox”>
  18.     <table width=“100%” cellspacing=“4″ cellpadding=“3″ style=margin-top:10px;>
  19.         <thead>
  20.         <tr bgcolor=“#E7E7E7″>
  21.             <td align=“center”><input type=“checkbox” value=“check_all_message” id=“check_all_message” name=“check_all_message”></td>
  22.             <td>From</td>
  23.             <td>Subject</td>
  24.             <td>Date</td>
  25.             <td align=“center”><img src=“images/attach.png”></td>
  26.             <td align=“center”><img src=“images/star.png”></td>
  27.         </tr>
  28.         </thead>
  29.         <tbody>
  30.                 
  31.         <tr id=“2″>
  32.             <td align=“center”><input type=“checkbox” value=“2″ id=“check_message” name=“check_message”></td>
  33.             <td>
  34.                                         <a id=“link” class=“2″ href=“message_read”>
  35.                             Froogo                        </a>
  36.                                     </td>
  37.             <td>No reply :: Delivery Notice From Frooogo</td>
  38.             <td>Oct 20, 2011</td>
  39.             <td></td>
  40.             <td></td>
  41.         </tr>
  42.                 
  43.         <tr id=“3″>
  44.             <td align=“center”><input type=“checkbox” value=“3″ id=“check_message” name=“check_message”></td>
  45.             <td>
  46.                                         <a id=“link” class=“3″ href=“message_read”>
  47.                             rajib kumar                        </a>
  48.                                     </td>
  49.             <td>reply mail</td>
  50.             <td>Oct 20, 2011</td>
  51.             <td></td>
  52.             <td></td>
  53.         </tr>
  54.                 
  55.         <tr id=“4″>
  56.             <td align=“center”><input type=“checkbox” value=“4″ id=“check_message” name=“check_message”></td>
  57.             <td>
  58.                                         <a id=“link” class=“4″ href=“message_read”>
  59.                             Mehedi Hasan                        </a>
  60.                                     </td>
  61.             <td>baba</td>
  62.             <td>Oct 20, 2011</td>
  63.             <td></td>
  64.             <td></td>
  65.         </tr>
  66.                 </tbody>
  67.     </table>
  68. </form>
  69. <script>
  70. jQuery(“#delete”).live(“click”,function(){
  71.     var chkMail=“”;
  72.     $(“#messageBox #check_message”).each(function(i){
  73.                 if($(this).attr(“checked”)){
  74.                     chkMail += “>”+$(this).attr(“value”);
  75.                 }
  76.                 
  77.     });
  78.     var answer = confirm(“Confirm to delete?”)
  79.     if (answer){
  80.         alert(“The selected values are: ”+chkMail);
  81.     }
  82.     else{
  83.         alert(“Thanks for sticking around!”)
  84.     }                        
  85. });
  86. </script>
  87.  
  88. </div>
  89. </body>
  90. </html>

Convert Currency Number to words in Yii Framework

This class in very needed who is working in web application. This class convert currency number to word.

Example: 100 to one hundred. (Its really very beautiful)

1. Copy and Paste this class in you Controller Class

  1. public function int_to_words($x)
  2.    {       
  3.        $nwords = array(“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”, “ten”, “eleven”, “twelve”, “thirteen”, “fourteen”, “fifteen”, “sixteen”, “seventeen”, “eighteen”, “nineteen”, “twenty”, 30 => “thirty”, 40 => “forty”, 50 => “fifty”, 60 => “sixty”, 70 => “seventy”, 80 => “eighty”, 90 => “ninety” );
  4.        if(!is_numeric($x))
  5.        {
  6.            $w = ‘#’;
  7.        }else if(fmod($x, 1) != 0)
  8.        {
  9.            $w = ‘#’; 
  10.        }else{
  11.            if($x < 0)
  12.            {
  13.                $w = ‘minus ’;
  14.                $x = -$x;
  15.            }else{
  16.                $w = ;
  17.            } 
  18.            if($x < 21)
  19.            {
  20.                $w .= $nwords[$x];
  21.            }else if($x < 100)
  22.            {
  23.                $w .= $nwords[10 * floor($x/10)];
  24.                $r = fmod($x, 10); 
  25.                if($r > 0)
  26.                {
  27.                    $w .= ‘-’. $nwords[$r];
  28.                }
  29.            } else if($x < 1000)
  30.            {
  31.                $w .= $nwords[floor($x/100)] .‘ hundred’; 
  32.                $r = fmod($x, 100);
  33.                if($r > 0)
  34.                {
  35.                    $w .= ‘ and ’. $this->int_to_words($r);
  36.                }
  37.            } else if($x < 100000) 
  38.            {
  39.                $w .= $this->int_to_words(floor($x/1000)) .‘ thousand’;
  40.                $r = fmod($x, 1000);
  41.                if($r > 0)
  42.                {
  43.                    $w .= ‘ ’; 
  44.                    if($r < 100)
  45.                    {
  46.                        $w .= ‘and ’;
  47.                    }
  48.                    $w .= $this->int_to_words($r);
  49.                } 
  50.            } else {
  51.                $w .= $this->int_to_words(floor($x/100000)) .‘ lakh’;
  52.                $r = fmod($x, 100000);
  53.                if($r > 0)
  54.                {
  55.                    $w .= ‘ ’; 
  56.                    if($r < 100)
  57.                    {
  58.                        $word .= ‘and ’;
  59.                    }
  60.                    $w .= $this->int_to_words($r);
  61.                } 
  62.            }
  63.        }
  64.        return $w;
  65.    }

2. Now see carefully how to use int_to_words() function to get exact result. Suppose you want to use it in actionCreate() function. It is so simple to use.

  1. public function actionCreate()
  2. {
  3.    $total_sale_price_inword = $this->int_to_words(10000);
  4.    echo $total_sale_price_inword;
  5. }

now echo $total_sale_price_inword will be display ten thousand.

 

Enjoy It.

If any problem feel free to contact with me.

http://www.rajibkumar.com

me@rajibkumar.com

 

Select data in Yii Framework (Very Usefull)

This is very usefull code for new user’s who use yii framework.

Formula 1:

Select data from  table with condition, it is very easy :

  1. $command = Yii::app()->db->createCommand();
  2. $chkSaleOrderProduct = $command->select(‘column_name’)->from(table_name)->where(“column_name=value”)->queryAll();

After running this code you can get result in

  1. echo $chkSaleOrderProduct[0][column_name];

I think this code helps you.

 

Rajib Kumar Rakhmit

http://www.rajibkumar.com