Sunday, November 17, 2013

How to get current page URL in Codeigniter?

For getting complete URL:

By using the current_url() method we can get the current page URl of the page.

Example:

$page_url=current_url();
echo $page_url;

For getting URI segments:

By using the following statement we can get the segments in the URI.

Syntax:

$this->uri->segment(n);
           where n=1 for controller
                     n=2 for method
                     n=3,4,5,6........ for parameters.
 
Example:

URL:   http://localhost/nareshphp/login/home

echo $this->uri->segment(1); //It will returns login as output

echo $this->uri->segment(2); //It will returns home as output


For getting current controller and method names:

$this->router->fetch_class(); //It will returns controller name

$this->router->fetch_method(); //It will return current method name.


Keep Smiling....

Tuesday, August 20, 2013

What is Mail Cron?

Mail Cron:
Mail Cron is a UNIX command used for sending mails to customers at time intervals through SMTP's.
Cron Syntax:
/usr/bin/GET  http://your site or mail sending area complete path
Example:
/usr/bin/GET  http://www.naresh-php.com/index.php/mail/send_mails/mails_list

Keep Smileing...

Monday, August 12, 2013

How to display clock using Javascript in PHP?

The following snippet of code display current time in your web page.

JavaScript
 <script  type="text/javascript" >
   function updateClock () {
    var currentTime = new Date();
    var month = currentTime.getMonth();
    var date = currentTime.getDate();
    var year = currentTime.getFullYear();
    var currentHours = currentTime.getHours ();
    var currentMinutes = currentTime.getMinutes ();
    var currentSeconds = currentTime.getSeconds ();
   
    var months = new Array(
    "January", "February", "March", "April",
    "May", "June", "July", "August", "September",
    "October", "November", "December");
   
    // Pad the minutes and seconds with leading zeros, if required
    currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
    currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
   
    var currentTimeString = months[month]+" "+ date +", "+year+" "+currentHours + ":" + currentMinutes + ":" + currentSeconds;
   
    document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}
</script>

HTML Code
<body onload="updateClock(); setInterval('updateClock()', 1000 )">
<div id="clock" align="center" style="color:#F30; font-weight:100;">&nbsp;</div>
</body>


Have a nice day....

Simple captcha using jQuery in PHP?


PHP Code

$length = 6;
$captcha = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);


HTML Code

<input type="text" name="captcha" value="<?php echo $captcha; ?>"  id="captcha" />

Enter the code above here :

<input type="password" name="Enter Code" />

Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</td>


JS Code

<script>
function refreshCaptcha()
{
 var text = '';
    var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

    for(var i=0; i < 6; i++)
    {
        text += possible.charAt(Math.floor(Math.random() * possible.length));
    }
    $("#captcha").change().val(text);
}
</script>


Keep Smileing...

Friday, June 28, 2013

How to add menu to footere in wordpress?

The following single line code add in footer where you want to show menu bar.


Syantax:

<?php wp_nav_menu(array('menu' => 'name')); ?>
                          where name = Menu slug name.

Example:

<?php wp_nav_menu(array('menu' => 'my-custom-menu')); ?>

Wednesday, June 26, 2013

How to change Woocommerce products per page?

By adding the following one line code to your functions.php file, we will change the products per page in Woocommerce.
Now i would like to display 12 products in the place of regular 10 products.


add_filter('loop_shop_per_page',create_function('$cols','return 12;'),20);

Friday, June 21, 2013

Show cart contents / total at WooCommerce header in Wordpress?

Add the following bit of code to your header file exactly where you want to display the cart total items value.

<?php global $woocommerce; ?>
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?>
</a>

<!---Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)---->

<?php
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>

<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?>
</a>

<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
?>

Keep Smiling.
Naresh.

Thursday, June 20, 2013

How to add WooCommerce short codes in Wordpress Template files?

By using do_shortcode() function we can add the WooCommerce shortcode 
to the template files.
Syntax:
<?php echo do_shortcode( 'ShortCode' ); ?>
Example:
<?php echo do_shortcode( '[fblike]' ); ?>


Keep Smiling

Naresh.

How to display welcome note in Wordpress along with user name?

The following piece of code full fill your requirement.

<?php
global $current_user;
get_currentuserinfo();
if(isset($current_user->user_login))
{
    $name=$current_user->user_login;
    echo 'Welcome '.ucfirst($name);
}
else
{

}
?>

......................
Keep Smilimg.

Thursday, May 2, 2013

How to create dynamic select boxes in Codeigniter form using AJAX?

The follownig code clearly explains you how to dynamic select boxes usin AJAX in codeigniter.

VIEW:

<div class="slidtxt">Category :</div>
<div class="slidfield">
<select name="category" id="sc_get">
<option value="ap">Andhrapradesh</option>
<option value="tn">Tamilnadu</option>
<option value="kr">Karnataka</option>
<option value="kl">Kerala</option>
</select>
</div>

<div class="slidtxt">Sub Category :</div>
<div class="slidfield">
<select name="subcat" id="sc_show">

</select>
</div>

<script>
//Script for getting the dynamic values from database using jQuery and AJAX
$(document).ready(function() {
    $('#sc_get').change(function() {

var form_data = {
name: $('#sc_get').val()
};

$.ajax({
url: "<?php echo site_url('controller_name/method'); ?>",
type: 'POST',
dataType: 'json',
data: form_data,
success: function(msg) {
var sc='';
$.each(msg, function(key, val) {
sc+='<option value="'+val.sub_cat+'">'+val.sub_cat+'</option>';
});
$("#sc_show option").remove();
$("#sc_show").append(sc);
}
});
});
});
</script>




CONTROLLER:

public function get_subcat()
{
        $cat=$this->input->post('name');
        $table='subcat';
        $where=array('cat' => $cat);
        $data['sc_get']=$this->admin->get_where_data($table,$where);
        $sc=json_encode($data['sc_get']);
        echo $sc;
}


MODEL:

public function get_where_data($table,$where)
{
        $query=$this->db->get_where($table,$where);
        return $query->result_array();
}





...........................
Have a Great Day.
Keep Smiling....




Friday, April 5, 2013

How to raplace one page to another address ?

 By using the following Javascript we can redirect from current page to another address.
<script>
window.onbeforeunload = function () {
   location.replace('http://www.google.com');
   return "This session is expired and the history altered.";
}
</script>
Note: Placed in header is preferable one. 

Tuesday, April 2, 2013

In PHP, how to search a value existed or not in array?

By using in_array function we can knows the element existed or not in that array.

Syntax:

         in_array('search_array_value',$search_array);

Example:

$fruits=array('Apple','Bananna','grapes','Mango');  

In the above array fruits we want to know the array having 'Bananna' value or not!

 if (in_array('Bananna',$fruits))
        {
                   echo 'Fruits having Bananna';
        }
        else
        {
                  echo 'Fruits doesn't having Bananna';
        }

Monday, April 1, 2013

How to add confirmation box to forms using Javascript?

No need to worry, it's a simple task. By adding "onclick" function to submit buttons.
syntax:  
onclick="return confirm('Do you like to proceed?');"
Example: 
<input type="submit" name="submit" value="Submit" onclick="return confirm('Do you like to proceed?');">