Showing posts with label Codeignter. Show all posts
Showing posts with label Codeignter. Show all posts

Thursday, 17 March 2016

Helper Codeignter Convert Number into Button

Simple helper for convert number into some word in PHP especially for codeignter framework,

As long as you develop project you need some helper if you already know CI,  now i'm going to create Tutorial about convert number into some words using codeignter

here is my helper about it, give it name convert_status_helper.php

 <?php  
  'Pending',  
     2=> 'Approve 1',  
     3=> 'Reject 1',  
     4=> 'Approve 2',  
     5=> 'Reject 2',  
     6=> 'Approve Admin',  
     7=> 'Reject Admin',  
 */  
 if ( ! function_exists('test_method'))  
 {  
   function convert_to_colour($var = '')  
   {  
     if ($var=='1')  
     {  
      echo "<div class="external-event bg-green">  
 Pending</div>  
 ";  
     }  
     else if ($var=='2')   
     {  
       echo "<div class="external-event bg-yellow">  
 Approve 1</div>  
 ";  
     }  
   else if ($var=='3')   
     {  
       echo "<div class="external-event bg-black">  
 Reject 1</div>  
 ";  
  }  
     else if ($var=='4')   
     {  
       echo "<div class="external-event bg-aqua">  
 Approve 2</div>  
 ";  
     }  
   else if ($var=='5')   
     {  
       echo "<div class="external-event bg-black">  
 Reject 2</div>  
 ";  
  }  
     else if ($var=='6')   
     {  
       echo "<div class="external-event bg-red">  
 Approve Admin</div>  
 ";  
     }  
   else if ($var=='7')   
     {  
       echo "<div class="external-event bg-black">  
 Reject Admin</div>  
 ";  
  }  
     else   
     {  
      echo "<div class="external-event bg-black">  
 Pending</div>  
 ";  
     }  
   }    
 }  
 ?>  


in that helper convert number into button but if you need convert to words you can change it, open autoload we need autoload this helper like this

 $autoload['helper'] = array('convert_status');  

then i put in controller login and this is my controller

 <?php  
 if (!defined('BASEPATH'))  
   exit('No direct script access allowed');  
 class Login extends CI_Controller  
 {  
   function __construct()  
   {  
     parent::__construct();  
   }  
   public function index()  
   {  
      $this->load->view('login');  
   }  
 }  


and in your view you just need

 <?php echo convert_to_colour('1') ?>  


this helper help me alot when show status in multiple controller then i just call by conver_to_colour so this is my deisgn based on number

  1. Number  One For Button Pending Status
  2. Number  Two For Button Pending Approve 1
  3. Number  Three For Button Pending Reject 1
  4. Number  Four For Button Pending Approve 2
  5. Number  Five For Button Pending Reject 2
  6. Number  Six  For Button Approve Admin
  7. Number  Seven For Button  Reject Admin

in your view don't forget to use bootsrap framework, cause i use it tomake button become pretty
then this is my screen shot with status 1

Hope you understand lah what i'm talking about, thanks




Sunday, 6 March 2016

Create Auto Increment without setting in PHPMYADMIN using CI

well may be the title make you hard to understand, let me give you example of my work, please see my images bellow with circle in that form

well logic is i select id from table order by desc limit 1 then in view i add with number 1 then i will look like autoincrement but it's not, here is my database screen shoot

then in view show up with number 10, so let me show my code,
cCONTROLLER
 $data = array(  
                //pro_employee_id auto increment  
                'id'=>$this->Karyawan_model->getlastid(),  
                );  
 $this->template->load('template', 'pro_employee_form',$data);  

MODEL
 function getlastid()  
      {  
        $this->db->from('pro_employee');  
     $this->db->order_by("pro_employee_id", "desc");  
     $this->db->limit('1');   
     return $this->db->get()->row();    
      }  

VIEW 
 <?php  
           $maxid = 0;  
     if ($id) {  
       $maxid = $id->pro_employee_id;   
     }   
           ;?>  
            <input type="text" class="form-control" name="pro_employee_id" id="pro_employee_id" value="<?php echo $maxid+1 ?>" readonly />  

hope you understand what i'm telling in here, thanks for visiting me,
Cheers


Thursday, 18 February 2016

Google Maps in Codeignter

Well short tutorial in here will talk about google maps, show multiple marker using Codeignter which is came from databse, here is screen shoot !

well map show multiple marker around some city in my case it show in Lampung i just input 2 place on it, all you need when put marker in goolge maps is lat and lang, you can read more  at here 

Input new entri google maps when you logged as admin
the url login http://localhost/map/login to the dashboard

user : admin
pass : admin


Thanks for visiting me, all file you can get at here

Friday, 29 January 2016

Full Calender Using Codeignter Which is Came from Database

Well this is my screen shot for you , please see the url so you can goes to file later on will be upload to dropbox












then in controller i use select data using where clause please see in controller
 public function date()  
   {  
     $this->db->select('*');  
     $this->db->from('cu_date_cuti');  
     $this->db->where('cu_date_cuti_id','1');  
     $query = $this->db->get();  
     foreach ($query->result_array() as $row)  
       {  
          $new_row['title']=htmlentities(stripslashes($row['cu_date_id']));  
          $new_row['start']=htmlentities(stripslashes($row['cu_date_date']));  
          $row_set[] = $new_row;   
       }  
     echo json_encode($row_set);  
   }  


when you need to echo date in full calender you need to convert data to be json, for more information fullcalender is here

file you can grab here

Note : This is bassically configuration and you need to be familiar with codeignter


Saturday, 23 January 2016

Load All Varibales in every Controller Using Codeignter

This post for people know Codeignter been one year lah especially for me. This is about load same varibale each controller, please see script bellow

 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class Welcome extends CI_Controller {  
 public function read1()  
   {  
  $data['notif']=$this->Notif_model->get_all_notif(); //same varibale  
  }  
 public function read2()  
   {  
  $data['notif']=$this->Notif_model->get_all_notif(); //same varibale  
  }  
 public function read3()  
   {  
  $data['notif']=$this->Notif_model->get_all_notif(); //same varibale  
  }  
 }  

as you can see there are same varibale in every function, that's not clean code i guess !
so idecide to search about this issue then i found it
  1. GLOBAL VARIBALE
  2. EXTENDS CONTROLLER
after few hours digging on global varibale hard to learn then i leave it, focus on extends controller from stackoverflow here, yes stackoverflow is the best place to throw fuckin stress.

Then i make extends controller 
 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class AppKaryawan extends CI_Controller  
 {  
  /**  
  * @return void  
  **/  
  function __construct()  
  {  
  parent::__construct();  
  //load variable global  
  $this->data = array(  
       'notif' => $this->Notif_model->get_all_notif()  
     );  
  if (($this->session->userdata('cu_level') === 'Pegawai') or ($this->session->userdata('cu_level') === 'Manajer'))   
  {  
   return TRUE;  
  }  
  else  
  {  
   //show_404(); // OR   
   redirect('login');  
   return FALSE;  
  }  
  }  
 }  


Please see my extends above only for level Manajer, but ignore it lah it doesn't important. then let see the controller after extends controller this is will change like this
 public function read1()  
   {  
  $data = $this->data;   
  }  
 public function read2()  
   {  
  $data = $this->data;   
  }  
 public function read3()  
   {  
  $data = $this->data;   
  }   

Please compare the controller, yes the second controller is really lite bite clean but after think and quit some minute it tottally same, wtf ! cause each function should write the $data, how can i make it more clean, i'm open disscuss guys !

if you any trick please throw the code so people will understanding, so i will reblog it again to make more clean, Thanks for visiting me !

Happy Weekend 

Thursday, 21 January 2016

Get One Field in Codeignter

Get one field in Codeignter when we need to extract it in view or controller

here is controller
and here is model
Thanks for visiting me !

you can grab database is here

Tuesday, 19 January 2016

COUNT DIFFRENT 2 DATE IN MYSQL USING CODEIGNTER

now i'm working on about date and time and will give you short tutorial about count diffrent date between two dates, well i'm fun using codeignter then spend some hours i found some blog intresting and help me a lot

check this out the authtoor tell how to count 2 date, so i change it to CODEIGNTER

first go to your and create datediff_helper.php
 <?php  
 // Set timezone  
  date_default_timezone_set("UTC");  
  // Time format is UNIX timestamp or  
  // PHP strtotime compatible strings  
  function dateDiff($time1, $time2, $precision = 6) {  
   // If not numeric then convert texts to unix timestamps  
   if (!is_int($time1)) {  
    $time1 = strtotime($time1);  
   }  
   if (!is_int($time2)) {  
    $time2 = strtotime($time2);  
   }  
   // If time1 is bigger than time2  
   // Then swap time1 and time2  
   if ($time1 > $time2) {  
    $ttime = $time1;  
    $time1 = $time2;  
    $time2 = $ttime;  
   }  
   // Set up intervals and diffs arrays  
   $intervals = array('year','month','day','hour','minute','second');  
   $diffs = array();  
   // Loop thru all intervals  
   foreach ($intervals as $interval) {  
    // Create temp time from time1 and interval  
    $ttime = strtotime('+1 ' . $interval, $time1);  
    // Set initial values  
    $add = 1;  
    $looped = 0;  
    // Loop until temp time is smaller than time2  
    while ($time2 >= $ttime) {  
     // Create new temp time from time1 and interval  
     $add++;  
     $ttime = strtotime("+" . $add . " " . $interval, $time1);  
     $looped++;  
    }  
    $time1 = strtotime("+" . $looped . " " . $interval, $time1);  
    $diffs[$interval] = $looped;  
   }  
   $count = 0;  
   $times = array();  
   // Loop thru all diffs  
   foreach ($diffs as $interval => $value) {  
    // Break if we have needed precission  
    if ($count >= $precision) {  
     break;  
    }  
    // Add value and interval  
    // if value is bigger than 0  
    if ($value > 0) {  
     // Add s if value is not 1  
     if ($value != 1) {  
      $interval .= "s";  
     }  
     // Add value and interval to times array  
     $times[] = $value . " " . $interval;  
     $count++;  
    }  
   }  
   // Return string with times  
   return implode(", ", $times);  
  }  
 ?>  




Then goes to autoload.php
 $autoload['helper'] = array('datediff');  


Then this is the controller
 <?php  
 if (!defined('BASEPATH'))  
   exit('No direct script access allowed');  
 class Login extends CI_Controller  
 {  
   function __construct()  
   {  
     parent::__construct();  
    }  
   public function index()  
   {  
      $this->template->load('template', 'login');  
   }  
 public function diffdate()  
   {  
     echo dateDiff('00:57:42','07:30:00');  
   }  
 }  
 </textare>  


The results here








You can grab helper is here




Sunday, 17 January 2016

Change format date in mysql to indonesian format

 well quick tutorial about change date mysql to indonesia date using codeignter, well copy paste this script bellow, give it name tgl_indonesia_helper.php put inside helper folder

 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');  
 if ( ! function_exists('tgl_indo'))  
 {  
  function tgl_indo($tgl)  
  {  
  $ubah = gmdate($tgl, time()+60*60*8);  
  $pecah = explode("-",$ubah);  
  $tanggal = $pecah[2];  
  $bulan = bulan($pecah[1]);  
  $tahun = $pecah[0];  
  return $tanggal.'-'.$bulan.'-'.$tahun;  
  }  
 }  
 if ( ! function_exists('bulan'))  
 {  
  function bulan($bln)  
  {  
  switch ($bln)  
  {  
   case 1:  
   return "Januari";  
   break;  
   case 2:  
   return "Februari";  
   break;  
   case 3:  
   return "Maret";  
   break;  
   case 4:  
   return "April";  
   break;  
   case 5:  
   return "Mei";  
   break;  
   case 6:  
   return "Juni";  
   break;  
   case 7:  
   return "Juli";  
   break;  
   case 8:  
   return "Agustus";  
   break;  
   case 9:  
   return "September";  
   break;  
   case 10:  
   return "October";  
   break;  
   case 11:  
   return "November";  
   break;  
   case 12:  
   return "Desember";  
   break;  
  }  
  }  
 }  


then don't forget to load in load helper in autoload.php like this

 $autoload['helper'] = array('tgl_indonesia');  


Then goes to your controller welcome copy and paste this
 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class Welcome extends CI_Controller {  
  public function index()  
  {  
   echo tgl_indo ('2016-02-11');   
  //$this->load->view('welcome_message');  
  }  
 }  


 then this the results,


Thanks for reading me !

Tuesday, 24 November 2015

Resize and Crop Before Upload to Server Using Codeignter

Developers always create CRUD i guess, today i will give short and quick tutorial about upload image with resize and crop to database using codeignter, the inspiration came from here

So i override all based on my needed, here is screen shot ignore the images















Well in that form i add up one input type box just for train my self if in the future will have alot of field, actually i just insert data image and name to table

Controller

View


Thanks for reading my blog hope this help you, sorry for uncomfortable

Database can download at here
Project can download here


Friday, 13 November 2015

Show Detail in Modal Bootsrap which Came From Database Using Codeignter

As developers we just Create, Read, Edit, Delete for me now on, but will be more than that cause i'm still newbie, so let me give short tutorial about show data in modal bootsrap using framework codeigniter, check this out

First create database blog and also table list_student

 -- phpMyAdmin SQL Dump  
 -- version 4.2.11  
 -- http://www.phpmyadmin.net  
 --  
 -- Host: 127.0.0.1  
 -- Generation Time: 13 Nov 2015 pada 11.15  
 -- Versi Server: 5.6.21  
 -- PHP Version: 5.6.3  
 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";  
 SET time_zone = "+00:00";  
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;  
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;  
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;  
 /*!40101 SET NAMES utf8 */;  
 --  
 -- Database: `blog`  
 --  
 -- --------------------------------------------------------  
 --  
 -- Struktur dari tabel `list_student`  
 --  
 CREATE TABLE IF NOT EXISTS `list_student` (  
 `id` int(11) NOT NULL,  
  `title` varchar(250) NOT NULL,  
  `desc` text NOT NULL  
 ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;  
 --  
 -- Dumping data untuk tabel `list_student`  
 --  
 INSERT INTO `list_student` (`id`, `title`, `desc`) VALUES  
 (1, 'This is Student Title 1', 'Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.'),  
 (2, 'This is Student Title 2', 'Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.');  
 --  
 -- Indexes for dumped tables  
 --  
 --  
 -- Indexes for table `list_student`  
 --  
 ALTER TABLE `list_student`  
  ADD PRIMARY KEY (`id`);  
 --  
 -- AUTO_INCREMENT for dumped tables  
 --  
 --  
 -- AUTO_INCREMENT for table `list_student`  
 --  
 ALTER TABLE `list_student`  
 MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=3;  
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;  
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;  
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;  

Then create controller like this

 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class Modal extends CI_Controller  
 {  
   public function index()  
   {  
     $data['modal'] = $this->modal_bootsrap->modal();  
     $this->load->view('modal', $data);  
   }  
   public function detail()  
   {  
     $id       = $this->input->post('id');  
     $data['detail'] = $this->modal_bootsrap->detail($id);  
     $this->load->view('detail', $data);  
   }  
 }  
Here is view came function index
 <html>       
      <head>  
 <title>CRUD DROPZONE</title>  
 <link href="<?php echo base_url() ?>asset/css/bootstrap.min.css" rel="stylesheet">  
  <script type='text/javascript'>  
      //auto complete depan  
      var site = "<?php echo site_url();?>";   
      var  base_url = '<?=base_url()?>';  
 </script>  
 <script src="<?php echo base_url() ?>asset/js/jquery.min.js"></script>  
 <script src="<?php echo base_url() ?>asset/js/bootstrap.min.js"></script>  
 <script src="<?php echo base_url() ?>asset/js/dropzone.js"></script>  
 <script src="<?php echo base_url() ?>asset/js/ajax.js"></script>  
 <script src="<?php echo base_url() ?>asset/js/ajaxdropzone.js"></script>  
 <link href="<?php echo base_url()?>asset/css/bootstrap.min.css" rel="stylesheet">  
 <link href='<?php echo base_url();?>asset/css/dropzone.css' rel='stylesheet' />  
 </head>  
      <body>  
       <?php   
                 foreach ($modal->result() as $row) { ?>  
 <a href="" class="btn btn-lg btn-success"  data-toggle="modal" href="#basicModal" data-whatever="<?php echo $row->id ?>"><?php echo $row->title ?></a>  
 <br>  
                <br>  
           <?php   
            } ?>  
 <div class="modal fade" id="basicModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">  
   <div class="modal-dialog">  
     <div class="modal-content">  
       <div class="modal-header">  
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>  
       <h4 class="modal-title" id="myModalLabel">  
 Modal title</h4>  
 </div>  
 <div class="modal-body" >  
                     <div id="detailstudent">  
                     </div>  
 </div>  
 <div class="modal-footer">  
         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>  
     </div>  
 </div>  
 </div>  
 </div>  
 </body>  
 </html>  

Model is here
 <?php  
 if (!defined('BASEPATH'))  
   exit('No direct script access allowed');  
 class modal_bootsrap extends CI_Model  
 {  
   function modal()  
   {  
     return $this->db->get('list_student'); // Produces: SELECT * FROM mytable  
   }  
   public function detail()  
   {  
     $id = $this->input->post('id');  
     return $this->db->query("SELECT * FROM list_student where id='$id'");  
   }  
 }  


Then don't forget making ajax cause it will handle data in modal bootsrap which we load file inside modal with tag id="detailstudent"
 $(function() {   
  $('#basicModal').on('shown.bs.modal', function(event) {  
      var button = $(event.relatedTarget)   
      var id = button.data('whatever')   
      var modal = $(this);  
      var dataString = 'id=' + id;  
   $.ajax({  
         type:"POST",  
         url: base_url + "modal/detail",  
         data: dataString,    
         success: function(data) {  
    //console.log(data);  
          $("#detailstudent").html(data);  
         },  
         error: function(jqXHR, exception) {  
           alert('error ajax');  
         }  
     })  
 });  
 });  

This tutorial came from here , oh yea almost forget to configuration autoload.php
 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 /*  
 | -------------------------------------------------------------------  
 | AUTO-LOADER  
 | -------------------------------------------------------------------  
 | This file specifies which systems should be loaded by default.  
 |  
 | In order to keep the framework as light-weight as possible only the  
 | absolute minimal resources are loaded by default. For example,  
 | the database is not connected to automatically since no assumption  
 | is made regarding whether you intend to use it. This file lets  
 | you globally define which systems you would like loaded with every  
 | request.  
 |  
 | -------------------------------------------------------------------  
 | Instructions  
 | -------------------------------------------------------------------  
 |  
 | These are the things you can load automatically:  
 |  
 | 1. Packages  
 | 2. Libraries  
 | 3. Drivers  
 | 4. Helper files  
 | 5. Custom config files  
 | 6. Language files  
 | 7. Models  
 |  
 */  
 /*  
 | -------------------------------------------------------------------  
 | Auto-load Packages  
 | -------------------------------------------------------------------  
 | Prototype:  
 |  
 | $autoload['packages'] = array(APPPATH.'third_party', '/usr/local/shared');  
 |  
 */  
 $autoload['packages'] = array();  
 /*  
 | -------------------------------------------------------------------  
 | Auto-load Libraries  
 | -------------------------------------------------------------------  
 | These are the classes located in the system/libraries folder  
 | or in your application/libraries folder.  
 |  
 | Prototype:  
 |  
 |     $autoload['libraries'] = array('database', 'email', 'session');  
 |  
 | You can also supply an alternative library name to be assigned  
 | in the controller:  
 |  
 |     $autoload['libraries'] = array('user_agent' => 'ua');  
 */  
 $autoload['libraries'] = array('database', 'email', 'session');  
 /*  
 | -------------------------------------------------------------------  
 | Auto-load Drivers  
 | -------------------------------------------------------------------  
 | These classes are located in the system/libraries folder or in your  
 | application/libraries folder within their own subdirectory. They  
 | offer multiple interchangeable driver options.  
 |  
 | Prototype:  
 |  
 |     $autoload['drivers'] = array('cache');  
 */  
 $autoload['drivers'] = array();  
 /*  
 | -------------------------------------------------------------------  
 | Auto-load Helper Files  
 | -------------------------------------------------------------------  
 | Prototype:  
 |  
 |     $autoload['helper'] = array('url', 'file');  
 */  
 $autoload['helper'] = array('url', 'file');  
 /*  
 | -------------------------------------------------------------------  
 | Auto-load Config files  
 | -------------------------------------------------------------------  
 | Prototype:  
 |  
 |     $autoload['config'] = array('config1', 'config2');  
 |  
 | NOTE: This item is intended for use ONLY if you have created custom  
 | config files. Otherwise, leave it blank.  
 |  
 */  
 $autoload['config'] = array();  
 /*  
 | -------------------------------------------------------------------  
 | Auto-load Language files  
 | -------------------------------------------------------------------  
 | Prototype:  
 |  
 |     $autoload['language'] = array('lang1', 'lang2');  
 |  
 | NOTE: Do not include the "_lang" part of your file. For example  
 | "codeigniter_lang.php" would be referenced as array('codeigniter');  
 |  
 */  
 $autoload['language'] = array();  
 /*  
 | -------------------------------------------------------------------  
 | Auto-load Models  
 | -------------------------------------------------------------------  
 | Prototype:  
 |  
 |     $autoload['model'] = array('first_model', 'second_model');  
 |  
 | You can also supply an alternative model name to be assigned  
 | in the controller:  
 |  
 |     $autoload['model'] = array('first_model' => 'first');  
 */  
 $autoload['model'] = array('dropzone_model','modal_bootsrap');  
Note 

  • I use codeignter without index.php so you need to remove index.php first to make all working fine
  • You can download database at here
  • File is here 
The way you download, please wait the click arrow in the top right then you can get file, 

If you have something to disscuss feel free to drop comment here, 


Thanks for visiting me

Thursday, 29 October 2015

MULTIPLE AUTOCOMPLETE IN CODEIGNTER

today i review my project then i found bugs i don't know why my autocomplete doesn't work well, so i fixed from here

so i fix from that tutorial cause that tutorial doesn't give you right autocomplete.

he just select wll data from table without spesific search so here is database acctually same but it's oke

DATABASSE please copy one by one
 CREATE TABLE `tb_kotaindonesia` (  
  `id` int(3) NOT NULL AUTO_INCREMENT,  
  `nama_kota` varchar(50) DEFAULT NULL,  
  `ibu_kota` varchar(50) DEFAULT NULL,  
  `keterangan` text,  
  PRIMARY KEY (`id`)  
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1  
 insert into `tb_kotaindonesia` (`id`, `nama_kota`, `ibu_kota`, `keterangan`) values('1','Medan','Medan','Kota medan adalah ibukota Provinsi Sumatera Utara');  
 insert into `tb_kotaindonesia` (`id`, `nama_kota`, `ibu_kota`, `keterangan`) values('2','Tapanuli Utara','Tarutung','Tapanuli Utara atau sering disebut TAPUT adalah sebuah tempat sejuk');  
 insert into `tb_kotaindonesia` (`id`, `nama_kota`, `ibu_kota`, `keterangan`) values('3','Jakarta','Jakarta','Jakarta Megapolitan Ibukota Negara Republik Indonesia');  
 insert into `tb_kotaindonesia` (`id`, `nama_kota`, `ibu_kota`, `keterangan`) values('4','Padang','Padang','Padang adalah tempat wisata jam gadang, disana terdapat jembatan yang membelah sungai musi');  
 insert into `tb_kotaindonesia` (`id`, `nama_kota`, `ibu_kota`, `keterangan`) values('5','Deliserdang','Lubuk Pakam','Sebuah kota sebelum medan yang kita pijak pertama sekali jika lewat udara (Bandara Kualanamu).');  


Here is my controller, there is diffrent here please see
 $q = strtolower($_GET['term']);  
if refrensi above he didn't tell spesific data in table he just select all woithout key and where clasue in model,
 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');  
 class Kota extends CI_Controller  
 {  
   public function __construct() {  
     parent::__construct();  
     $this->load->model('mkota'); //load model mkota yang berada di folder model  
     $this->load->helper(array('url')); //load helper url  
   }  
   public function index()  
   {  
     $data['titel']='Multiple Output Autocomplete Jquery UI + CodeIgniter'; //varibel title  
     $this->load->view('vkota',$data); //tampilan awal ketika controller kota di akses  
   }  
   public function get_allkota() {  
     $q = strtolower($_GET['term']);  
     $query = $this->mkota->get_allkota($q); //query model  
     $kota    = array();  
     foreach ($query as $d) {  
       $kota[]   = array(  
         'label' => $d->nama_kota, //variabel array yg dibawa ke label ketikan kunci  
         'nama' => $d->nama_kota , //variabel yg dibawa ke id nama  
         'ibukota' => $d->ibu_kota, //variabel yang dibawa ke id ibukota  
         'keterangan' => $d->keterangan //variabel yang dibawa ke id keterangan  
       );  
     }  
     echo json_encode($kota);   //data array yang telah kota deklarasikan dibawa menggunakan json  
   }  
 }  

Model here is i give where clause so you can spesific select table in autocomplete
 <?php  
 class Mkota extends CI_Model {  
   function __construct() {  
     parent::__construct();  
   }  
   function get_allkota($kode) {  
     $this->db->like('nama_kota', $kode);  
     $res = $this->db->get('tb_kotaindonesia');  
     if ($res->num_rows() > 0) {   
       return $res->result();  
     }  
   }  
 }  
 ?>  
Hope you understand lah what i mean here, thanks for visiting me ! file can download right here Note : Please provide file in view if possible just use cdn cause i take in my project

Friday, 28 August 2015

MULTIPLE DELETE IMAGES IN FOLDER ALSO IN DATABASE

Tutorial about delete multiple images in folder also in database, let's quick

Here is Controller

 public function hapus($tes_id)  
   {  
   $images= $this-&gt;db-&gt;query("SELECT * FROM `testimonial` tes_id='$tes_id'")-&gt;row_array();  
    $image=$images['tes_image'];  
   $image1=$images['testi_img1'];  
   $image2=$images['testi_img2'];  
   $image3=$images['testi_img3'];  
   $image4=$images['testi_img4'];  
   $image5=$images['testi_img5'];  
   $image6=$images['testi_img6'];  
   $image7=$images['testi_photo'];  
   $image8=$images['tes_beforeafter'];  
    $file = array($image,$image1,$image2,$image3,$image4,$image5,$image6,$image7,$image8);  
   $arrlength = count($file);  
  for($x = 0; $x &lt; $arrlength; $x++) {  
  unlink('uploads/testimoni/' . $file[$x]);  
  }  
  $this-&gt;testimoni_model-&gt;hapus($tes_id);//  
  redirect ('admin/testimonial');   
 }  

Here is Model
 function hapus($tes_id)  
 {  
  $this-&gt;db-&gt;where('tes_id',$tes_id);  
  $this-&gt;db-&gt;delete('testimonial');  
 }   

Thanks for visiting me, hope this help your projects !

Regards !

Monday, 10 August 2015

How to save link in variable using codeignter

Hello this morning i will give short tutorial when you want to echo same href in your file.php i use codiegnter by the way, so here is my simple tutorial to make some href in echo


num_rows() < 3)
{
 echo "Tambah Data";
}
else
{
 echo "Tambah Data"; 
}
?>



Thanks for visiting me !


Friday, 7 August 2015

PREVENT BACK BUTTON AFTER LOGOUT USING CODIEGNTER

Hello i found my problem in my project and then solved, so i posted here hope someone will help from this post i found this easy tutorial here

 So i reblog in here First create this name it sukasukalo_helper.php and then put in your helper

output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
  $CI->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
  $CI->output->set_header('Pragma: no-cache');
  $CI->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
 }

then go to your config/autoload.php load it by autoload so you will not wasting time load many time


$autoload['helper'] = array('sukasukalo');

then put it in every function in your controller to prevent back after users log out

{ 
  //here calling the function in helper
  backButtonHandle();
  //to make your web secure put this check session, if session empty will throw to default controller
  if (($this->session->userdata('nama')=="")  and ($this->session->userdata('username')=="")) {
   redirect('welcome');
  }
  //it's just my simple project setting as you need i
  $name = $this->session->userdata('name');
  $data['name'] = $this->model_user->login($name)->row_array();
  $data['dataarticle'] = $this->model_article->all();
  $this->admin->load('template','admin-article',$data);
 }

If you feel this helpfull please share and if you any another way to make more secure and efisien just feel free to disccuss here Thanks for visitng me !

Monday, 27 July 2015

Backup Database Using Codeigniter

Hi how are you ? hope fully fine.

Sometime when you developing website then it need to be back up database no matter if your client knows how to backup from cpanel but if they don't know you need to make some function on it !


Here is my href menu

  • ">Back up Database
  • by looking controller we know why it will be, then here is my controller

    template->load('template','user/user');
     }
    public function backup()
    {
      $this->load->dbutil();
      $prefs = array(     
                    'format'      => 'zip',             
                    'filename'    => 'my_db_backup.sql'
                  );
      $backup =& $this->dbutil->backup($prefs); 
      $db_name = 'backup-on-'. date("Y-m-d-H-i-s") .'.zip';
            $save = 'pathtobkfolder/'.$db_name;
      $this->load->helper('file');
            write_file($save, $backup); 
      $this->load->helper('download');
            force_download($db_name, $backup);
    }
    
    }
    
    
    

    and click then menu then system will export database in zip file inside it you get ekstensiton .sql

    Share it if this help you, Thanks for visiting me !

    Happy Coding