/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { //latestnews $dataProvider = Post::model()->latestNews(); $dataProvider2 = Buku::model()->latestBook(); //$dataProvider3= Anggota::model()->rekomen(); $this->render('index', array('dataProvider' => $dataProvider, 'dataProvider2' => $dataProvider2)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Buku::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public static function jumlah($id_buku, $jml) { $buku = Buku::find($id_buku); $buku->jumlah = $jml; $buku->save(); }
<?php require_once "config.php"; $id = $_GET['id']; $buku = Buku::find($id); $buku->delete(); header('Location: index.php');
function hapus_buku($id) { $buku = new Buku(); return $buku->hapus_buku($id); }
<?php require_once "config.php"; $data = Buku::all(); ?> <!DOCTYPE html> <html> <head> <title>Php Active Record Sederhana</title> <link rel="stylesheet" href="bootstrap/css/bootstrap.css"> </head> <body> <div class="container"> <h1>Form Add</h1> <form action="insert.php" method="post"> <div class="form-group"> <label for="exampleInputEmail1">Nama Buku</label> <input type="text" class="form-control" id="nama" placeholder="Nama Buku" name="nama" required> </div> <div class="form-group"> <label for="exampleInputPassword1">Harga</label> <input type="number" class="form-control" id="harga" placeholder="Harga" name="harga" required> </div> <div class="form-group"> <input type="submit" class="btn btn-primary" value="Add This"> </div> </form>
<?php require_once "config.php"; $nama = $_POST['nama']; $harga = $_POST['harga']; $buku = new Buku(); $buku->nama = $nama; $buku->harga = $harga; $buku->save(); header('Location: index.php');
var $judul; var $harga; /* Sekumpulan Method yang ada didalam kelas buku */ function SetHarga($parameter) { $this->harga = $parameter; } /*br adalah tag html untuk membuat garis baru */ function GetHarga() { echo $this->harga . "<br/>"; } function SetJudul($parameter) { $this->judul = $parameter; } function GetJudul() { echo $this->judul . " <br/>"; } } $Fisika = new Buku(); $Matematika = new Buku(); $Fisika->setJudul("Fisika Dasar untuk Engineer"); $Matematika->setJudul("Matematika Dasar untuk Engineer"); $Fisika->setHarga(80000); $Matematika->setHarga(100000); $Fisika->getJudul(); $Fisika->getHarga(); $Matematika->getJudul(); $Matematika->getHarga();
public function excel() { // data $sekolah = Sekolah::data(); $buku = Buku::semua(); return View::make('excel.buku', compact('sekolah', 'buku')); }
public function postHapusCeklis() { // input $id = Input::get('id'); // perulangan for ($i = 0; $i < count($id); $i++) { // data peminjaman $pinjam = Peminjaman::set($id[$i]['value']); // id buku $id_buku = $pinjam->id_buku; // data buku $buku = Buku::set($id_buku); // jumlah peminjaman $jml_pinjam = $pinjam->jumlah; // jumlah sisa $jml_sisa = $buku->jumlah; // jumlah peminjaman + jumlah sisa $total = $jml_pinjam + $jml_sisa; // rubah jumlah buku Buku::jumlah($id_buku, $total); // hapus data peminjaman Peminjaman::hapus($id[$i]['value']); } }
<?php class Buku { /* Variabel yang ada didalam kelas buku */ var $judul; var $harga; /*br adalah tag html untuk membuat garis baru */ function getHarga() { echo $this->harga . "<br/>"; } function getJudul() { echo $this->judul . " <br/>"; } /* Fungsi Spesial Construct didalam kelas buku */ function __construct($parameter1, $parameter2) { $this->judul = $parameter1; $this->harga = $parameter2; } } $Fisika = new Buku("Fisika Dasar untuk Engineer", 85000); $Matematika = new Buku("Matematika Dasar untuk Engineer", 95000); $Fisika->getJudul(); $Fisika->getHarga(); $Matematika->getJudul(); $Matematika->getHarga();