Welcome to my next tutorial. Before i go further in update sql statement, there is an important thing to know about what is controller, method and arguments. Open up your browser, go to localhost and folder containing codeigniter. You will have something like this :
http://localhost/ci
For your information, that address comes from this URL :
http://localhost/ci/index.php/welcome/index
Let me show the split of the address above :
- localhost = domain
- ci = folder
- index.php = index file
- welcome = controller
- index = method
Welcome controller as you already know comes from the file :
application/controller/welcome.phpSo wheres the method comes from? Well, if you open up welcome.php, it will look like this.
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url');
}
public function index() {
$this->load->view('welcome_message');
}
//buat method baru
public function papar1() {
echo 'wahaaa';
echo '<br />'.anchor('', 'home');
}
public function papar2() {
$this->load->view('test');
}
public function papar3() {
//kali ni kita akan pass variable dari controller ke views
$data['lk'] = 'passing data dari controller ke views';
$this->load->view('passing', $data);
}
public function dbase() {
//load database
$this->load->database();
//load model
$this->load->model('orang');
//load helper
$this->load->helper('form');
//process a form
if(isset($_POST['save'])) {
$nama = $_POST['nama'];
$tel = $_POST['tel'];
$result = $this->orang->insert(array('nama' => $nama, 'telefon' => $tel));
if($result) {
$data['info'] = 'success insert data';
} else {
$data['info'] = 'please try again later';
}
}
$data['query'] = $this->orang->GetAll(NUll, NULL);
$this->load->view('database', $data);
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
Look at the "public function somefunction() {}", that is the method in a controller. So where comes the arguments?
Look at this URL
http://localhost/ci/index.php/welcome/update/1
Its still the same, just follow the concept.
- localhost = domain
- ci = folder
- index.php = index file
- welcome = controller
- update = method
- 1 = argument
http://localhost/ci/index.php/welcome/update/1/as/qwe/23/56Its still the same thing, except, whatever comes after method, all of it were an argument..
- localhost = domain
- ci = folder
- index.php = index file
- welcome = controller
- update = method
- 1 = argument
- as = argument
- qwe = argument
- 23 = argument
- 56 = argument