Skip to main content

Posts

Final Keyword in PHP

Final method: A final method is a method that cannot be overridden. To declare a method as final, you need to prefix the function name with the ‘final’ keyword. eg: class Teacher {     final public function attendance() {       echo "Teacher attendance called";    } } class Student extends Teacher {    //this will cause Compile error    public function attendance() {        echo "Student attendance called";    } } $st = new Student(); $st->attendance(); Results in Fatal error: Cannot override final method Teacher::attendance() final class: A final class is a class that cannot be extended. To declare a class as final, you need to prefix the ‘class’ keyword with ‘final’. Example below. final class Teacher {    public function attendance() {       echo "Teacher attendance called";    } } //this will cause Compile error class Studen...

Mysql Union

The UNION set operator is used for combining data from two tables which have columns with the same datatype.When a UNION is performed the data from both tables will be collected in a single column having the same datatype. Rules: The number of columns appears in the corresponding SELECT statements must be equal. The columns appear in  the corresponding positions of each SELECT statement must have the same data type or at least convertible data type. You cannot use the union operator on text and image columns. Notes: Union -- returns with no duplicate rows Union all -- retruns with duplicate rows (No. of rows returned = No. of rows in Query1 + No. of rows in Query 2) Example: Suppose you want to combine data from the  student and teacher tables into a single result set, you can UNION operator as the following query: SELECT studentNumber id, contactLastname name FROM student UNION SELECT teacherNumber id,firstname name FROM teacher Here is the output...

Searching with Ajax pagination Cakephp

Searching with Ajax pagination Cakephp Step 1 : View File <script> $(document).ready(function(){ $(".pagination a, .header a").on('click',function(){ $('#content').load(unescape($(this).attr("href")),function(){ }); return false;   }); }); </script> <div id="content"> <?php echo $this->Form->create('User',array('type'=>'GET')); echo $this->Form->input('User.name',array('id'=>'name','error'=>array('class'=>'error'),                     'required'=>false,'value'=>@$_GET['data']['User']['name'])); echo $this->Form->input('User.email',array('id'=>'email','error'=>array('class'=>'error'),                     'required'=>false,'value'=>@$_GET['data'...

Cakephp Ajax Pagination

Cakephp Ajax Pagination Cakephp Ajax pagination works same like normal pagination , the difference is that it load the pages without refreshing Controller index function public function index(){         $this->paginate = array('limit'=>5,'order'=>'User.id desc');   $userDetail = $this->paginate('User'); $this->set('userDetail',$userDetail); if($this->RequestHandler->isAjax()){ // check the type of request $this->layout = ''; $this->autoRender = false; $this->render('index');  // render the same view } } User index view // script to load page by ajax <script> $(document).ready(function(){ $(".pagination a, .header a").on('click',function(){ $('#content').load(unescape($(this).attr("href")),function(){ }); return false;   }); }); </script> <div id="content"> // show the ...

Check All by jQuery

Check All by jQuery Method 1:  $(document).ready(function() {     $('#selectAll').click(function(event) {         if(this.checked) { // check select status             $('.checkbox1').each(function() {                 this.checked = true;  //select all checkboxes with class "checkbox1"                         });         }else{             $('.checkbox1').each(function() {                 this.checked = false; //deselect all checkboxes with class "checkbox1"                                 });               }     });   }); Html <div> <input type="checkbox" id="selectAll"...

Sort Table by jquery

1.  Sort table first column by jQuery Create a function sortTable. Pass table id & order function sortTable(table, order) {             var asc   = order === 'asc',             tbody = table.find('tbody');          tbody.find('tr').sort(function(a, b) {         if (asc) {             return $('td:first', a).text().localeCompare($('td:first', b).text());         } else {             return $('td:first', b).text().localeCompare($('td:first', a).text());         }     }).appendTo(tbody); } Call function when document loaded jQuery(document).ready(function() { sortTable($('#editable'),'asc'); }); 2. Sort the select option without empty value Html: <select id="contacts" class="filteroption" name="data[Candidateprofile][company]"> ...

How to add Validation rule in jQuery validation Plugin

How to add Validation rule in jQuery validation Plugin 1. Load the validate plugins <script src="js/jquery.validate.js"></script> 2. Now call the jQuery validate method <script> $(document).ready(function(){ // Add your own custom method  $("#old_password").rules('add',{remote:"check_password.php",  messages: {remote: "Passwords do not match"}});  $("#confirm_password").rules('add',{equalTo: "#password",   messages: {equalTo: "New password and confirm password do not match"}}); }); controller action $count=$this->Member->find('count',array( 'conditions'=>array('Member.password'=>md5($_GET['oldPass']), 'Member.id'=>$this->Session->read('Member.id'))));    if($count>0)    { echo 'true'; die;    } else { echo 'false'; die;   } // valid...