In Association with Amazon.in   Flipkart

Friday, August 30, 2019

codeignator model sample method statements

Calling model user define ganesh funs:::-
****************************************
To load view page:
==================
$data='Array values';
$this->load->view('admin/users', $data);
----------------------------------

To redirect some page:
======================
           redirect(base_url().'admin/dashboard', refresh);
----------------------------------

To Fetch data:
======================
    $sql1="SELECT * FROM `users` WHERE md5(id) = '$id' AND status <> 'DONE';";
     $resp1=$this->user_model->run_query($sql1);
     if($resp1->num_rows()) {
      foreach ($resp1->result() as $row)
// print row data;
}
--------------------------

To insert data Row:
===================
            $this->user_model->insertRow('users', $data);

------------------------------

To update data Row:
=================
$this->user_model->updateRow('table_name', 'where_field', $where_value, $array_values);
-----------------------------

To Delete Data Row:
===============
$this->user_model->delete_id('table_name', 'where_field', $where_value, $array_values);

--------------------------------------
To Send Email Message:
=======================
$this->user_model->send_email_msg($fromemail, $toemail, $Subject, $emailmsg);

--------------------------------------

To Get Count:
=============
$data['tot_res']= $this->user_model->getValueQry("SELECT count(*) as val FROM `orders` WHERE status = 'Active'");
---------------------------------

To upload file:
===================
      // --------- for inserting Qfile
         foreach($_FILES as $name => $fileInfo) {
               if(!empty($_FILES[$name]['size'])){
              $filename=$_FILES[$name]['name'];
            $exp=explode('.', $filename);
            $ext=strtolower(end($exp));

                  if($name === 'photo') {
                    if($ext === 'jpeg' || $ext === 'jpg' || $ext === 'png'){

                      $newname=  time()."_".$filename;
                      $tmpname= $_FILES[$name]['tmp_name'];

                       if(move_uploaded_file($tmpname,"media/photos/".$newname)) {
                       $data['photo']=$newname;
                 //      $this->user_model->updateRow('tnm', 'trf_id', $trf_id, $ddoc);
                     }
                   }
                 }
}}
------------------------------------------

To Set Session Data:
====================
             $this->session->set_userdata('admin_data',$return);
-------------------------------

To get/print session value:
=============================
             $admin_id = $this->session->admin_data->id;
-------------------------------

To set onetime session message:
=================================
                 $this->session->set_flashdata("messagePr", '<div class="notification error closeable"><p><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Login Failed.. Please try again..!</p><a class="close" href="#"></a></div>');
-------------------------------------

To print one time session message:
=================================
echo $this->session->flashdata('messagePr');
--------------------------------------------

To unset session data:
======================
$this->session->unset_userdata('admin_data');
---------------------------------

No comments:

Post a Comment


Related Posts Plugin for WordPress, Blogger...