Wednesday, 8 May 2019

Fatal error: Class CI_Session_files_driver contains 2 abstract methods...

Fatal error: Class CI_Session_files_driver contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (SessionHandlerInterface::open, SessionHandlerInterface::close) in C:\xampp\htdocs\connectosh\system\libraries\Session\drivers\Session_files_driver.php on line 49


According to my observation, This is only a bug that is related to session class.

Solution : Below are the some solution that will differently be overcome this bug.

Step 1: Stop XAMPP (Apache server) and then start.

Step 2: If not working then install Codeigniter again and use it as a fresh one..

Step 3: Go to in C:\xampp\htdocs\test\system\libraries\Session\SessionHandlerInterface.php .
            And comment code this.


Hope!!! Now your code will be work.



Tuesday, 7 May 2019

How to send HTML templates as an Email using SMTP in codeigniter

I am sharing this post which explains how to send HTML Template as an email using SMTP and PHPMailer in codeigniter.

Create a html template as per the requirement send this html page as per the project requirment.
Now we learn how to send Email by PHPMailer and Gmail Codeigniter.

Follow below steps we can implement it.



Step:1
First Create a HTML Template welcumemail.php Page which is suitable for your requirement.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Codeigniter</title>
</head>
<body>
<div class="wrapper">
<div style="margin:auto; text-align:center; width:625px;">
<p >Update your profile
Welcome Mail</p>
<p>Welcome to Codeigniter EmaIL!<br/></p>
</div>
</div>
</body>
</html>

Step:2
Create Controller Method for sending email.

public function sendemail()
{

   
            $data = array();
            $this->load->library('email');
            $subject='Welcome to Codeigniter';
       
            $htmlContent =  echo $this->load->view('welcumemail');
   
            $config['mailtype'] = 'html';
            $this->load->library('email');

            require("assets/testing/class.phpmailer.php");
            $email1='d.mehra@gmail.com';
            $mail = new PHPMailer();

            $mail->IsSMTP();
            $mail->Host = "xyz.in";
            $mail->SMTPAuth = true;
                    //$mail->SMTPSecure = "ssl";
            $mail->Port = 587;
            $mail->Username = "contact@xyz.in";
            $mail->Password = "xyz";

            $mail->From = "contact@xyz.in";
            $mail->FromName = "ABC";
            $mail->AddAddress("$email1");

            $mail->IsHTML(true);

            $mail->Subject = "Welcome ...";
            $mail->Body = ($htmlContent);
            
            $mail->Send();
            

            
        return True;
       

    }

         

Just Replace Your email ids,username,password and sending email using codeigniter.

Error:- $(...).modal is not a function.

$(...).modal is not a function.


This Error has so many solutions. Basically this is related to jquery and because model is related to bootstrap then we have to apply bootstrap js and bootstrap is depend on jquery then first we apply jquery.min.js and after that bootstrap.min.js.

like this.
    <script src="<?php echo base_url() ?>assets/global_assets/js/main/jquery.min.js"></script>
    <script src="<?php echo base_url() ?>assets/js/bootstrap.min.js"></script>

Solutions:

1. Apply above step means first jquery then bootstrap.
2. Check jquery is not included twice.
check with find in files using code igniter.



3. Change $.ajax(...) to JQuery.ajax(...).
4. Check using inspect element In console you can check error in which file.


Hope for this you can find error.



Saturday, 4 May 2019

Upgrade Android/IOS App using Codeigniter Restful Webservices(API)

What is Restful Webservices :- It is nothing just a function. webservices are the api that is used to communicate with different technologies. It is also called api (Application Programming Interface) used for provide the interface between different application.

Now I would like to share webservice of upgrade app and force update app.

Here we will writeapp_version_check() webservice in codeigniter controller or any framework.

Step:1 app_version_check()webservice



public function app_version_check()
{
$os = $this->input->get_post('os');
$app = $this->input->get_post('app');
$version = $this->input->get_post('version');
if($os == '' || $app == '' || $version == '' )
{

$status="error";
$message="Please Enter Required Fields";
$response=$this->response_msg($status,$message);
}
else
{
$upgrade_required = $this->Home_model->app_version_check($os,$app,$version);

if(!isset($upgrade_required))
{
$is_upgrade_required="True";
$message="New version of connectosh Available";
$response=$this->response_msg($status,$message);
}
else
{
$is_upgrade_required="False";
$message="No Need to update";
$response=$this->response_msg($status,$message);
}

}
$this->output
->set_content_type('application/json')
->set_output(json_encode($response));

}

There are 3 parameters os,app_name,version name pass in model and get the response in json format.

Step:2 app_version_check() Model

public function app_version_check($os,$app,$version)
{

$this->db->select('*');
$this->db->from('app_info');
$this->db->where('os',$os);
$this->db->where('app_name',$app);
$this->db->where('upgrade_code',$version);
$query=$this->db->get();
return $query->row();


}

Make sure you have a database of app_info table with 3 columns name('os','app_name','upgrade_code').

Now you can test the webservices using Postman.

Friday, 3 May 2019

Dynamic(Live) search using AJAX-Jquery-Codeigniter-Mysql based on different Tables.

In Today's Website, Most of the time we have to search something that should appear on page dynamically. For this we have to implement dynamic search also called live search using Ajax,Jquery in codeigniter with the use of Mysql database.
We will made a request from ajax and pass to the php controller and get a response in json object and will show the content on search box dynamically.  

Step:1  Firstly create a database:
Here I will create 2 table
1. tbl_user_detail

CREATE TABLE `tbl_user_detail` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL,
  `dob` varchar(100) NOT NULL,
  `email` varchar(100) NOT NULL,
  `phone` varchar(12) NOT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


2. tbl_news

CREATE TABLE `tbl_news` (
  `news_id` int(11) NOT NULL auto_increment,
  `news_section` int(11) NOT NULL,
  `news_title` varchar(255) NOT NULL,
  `news_category` int(11) NOT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1


Insert Some data in both Table.

Step:2 Now Create Codeigniter Controller Class (Main.php) .

In this controller class ,will create searching() function ,search keyword will pass on this function and in this function model class Home_model() will be called for database query logic and get back to response in json object.


<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Main extends CI_Controller 
{

  function __construct() 
{
    parent::__construct();
    $this->load->model('Home_model'); 
   
  }
 public function searching()
{
     $search=  $this->input->post('search_name');
     $search_cat_id = $this->input->post('search_cat');
     $query = $this->Home_model->searching($search,$search_cat_id);
   
     $view = '';
     foreach ($query as $sval) {
     if(isset($sval->news_id))
    {
        $title = implode(' ', array_slice(explode(' ', $sval->news_title), 0, 8));
          $view = $view .'<b><li onclick="addText(\''.$title.'\')">
         <a href = "'.base_url("news_detail/").base64_encode($sval->news_id).'/'.str_ireplace("", "-", $title).'">'.$title.'...'.'</a></li></b>';
      }
     
      else if(isset($sval->user_id))
      {
    
         $view = $view .'<b><li onclick="addText(\''.$sval->name.'\')">
         <a href = "'.base_url("user_profile/").base64_encode($sval->user_id).'/'.str_ireplace("", "-", $sval->name).'">'.$sval->name.'</a></li></b>';
      }
   
       
    }
    $view = $view . '<a href=""><li style="color:#0d4ca2;">See All Results</li></a>';
 
    echo $view;
}

}

Here will get 2 parameters from ajax, search_cat means category from which table you want to get response news or users and 2nd search keyword means what do you want to search from that tables.

Step:3 Now Create Codeigniter Model Class (Home_Model.php)

Create function name searching in model class.

  public function searching ($keyword,$search_cat_id)
    {
        if($search_cat_id == 1)
        {
            $table = 'tbl_user_detail';
            $cond = "name LiKE '%$keyword%'";
        }
        else if($search_cat_id == 2)
        {
            $table = 'tbl_news';
            $cond = "news_title LiKE '%$keyword%'";
        }
     
       $qry = $this->db->select('*')->from($table)
                    ->where($cond)
                   ->limit(7,0)

                    ->get()->result(); // select data like rearch value.
                    //echo $this->db->last_query(); die();
        return $qry;
    
    }

Step:4 Create View Page (HTML,CSS,Jquery,Ajax)

1. HTML

<select id="search_cat">
  <option value="1" selected>Users</option>
  <option value="2">News</option>
 </select>

<div id="searching">

<input type="text" class="form-control" name="category_search_name" id="category_search_name" placeholder="Search Users...">

<ul id="more_result"></ul>

</div>


2. CSS
<style>
#category_search_name {
         background-color: lightyellow;
         outline: medium none;
         padding: 8px;
         width: 500px;
         border-radius: 2px;
         -moz-border-radius: 3px;
         -webkit-border-radius: 3px;
         border-radius: 3px;
         border: 2px solid orange;
         }
  #more_result {
  list-style-type: none;
  padding: 0;
  margin: 0;
  position: absolute;
  width: 500px;
}

#more_result li  {
  border: 1px solid #ddd;
  margin-top: -1px; /* Prevent double borders */
  background-color: #f6f6f6;
  padding: 12px;
  text-decoration: none;
  font-size: 18px;
  color: black;
  display: block;
  
}
 #more_result li:hover {
    background:#4e6e84;
   
     transition: 0.5s ease;
    -webkit-transition:0.5s ease;
    -moz-transition:0.5s ease;
    -o-transition:0.5s ease;

    }
</style>


3. Jquery ,Ajax Script

<script>
  function addText(Textval){
    $('#category_search_name').val(Textval);
    $('#more_result').empty();
  }
 
  $(document).ready(function(){
    $('select#search_cat').on('change', function() {
      if(this.value == 1)
      {
          $('#category_search_name').attr('placeholder','Search Users...');
      }
     else if(this.value == 2)
      {
          $('#category_search_name').attr('placeholder','Search News...');
      }
     

});

    
    $('#category_search_name').on('keyup',function(){
     var search_cat = $( "#search_cat option:selected" ).val();
      var search_text = $('#category_search_name').val();
      if(search_text==""){
          $('#more_result').empty();
        }else{
        $.ajax({
          type: "POST", 
          url: "<?php echo base_url('main/searching')?>", 
          data: {search_name: search_text,search_cat: search_cat },
          success: function(html){
            console.log(html); 
            $("#more_result").html(html).show();
          }
        });
      }
    });
  });
</script>


Now you can do yourself.










        


How to upload All type of Files on AWS S3 using Codeigniter

Upload Files on Amazon S3 Bucket using Codeigniter. Before this,Firstly You have to know about the S3 Bucket. This is the simple Storag...