jQuery-PHP adalah sebuah PHP library yang memunggkinkan kita untuk mengitegrasikan syntax jQuery di PHP. Jika menggunakan Codeigniter maka salah satu cara yang dapat kita lakukan adalah dengan menuliskan kode jquery didalam view. atau jika ingin menyimpannya sebagai variable string di controller.
Liat contoh kode dibawah ini, itu adalah controller yang dapat memanipulasi halaman web menggunakan syntax jquery di php.
Untuk demo anda bisa lihat disini
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * jquery_php class * * @package default * @author Ibnu Daqiqil Id **/ class jquery_php extends Controller { function __construct() { parent::__construct(); } /** * Index function * * @return void * @author Ibnu Daqiqil Id **/ function index() { $this->load->view('jquery_client'); } function backend() { $this->load->plugin('jquery'); jQuery('#home')->html(date('Y-m-d h:m:s').' - Hellow World!!'); jQuery::getResponse(); } function backend2() { $this->load->plugin('jquery'); jQuery('#home')->html(date('Y-m-d h:m:s').' - Hellow World!!')->css('backgroundColor' , '#ff0000'); //jQuery::evalScript("alert('aaa')"); jQuery::addAction('click',"alert('aaa')"); jQuery::getResponse(); } function backend_event() { $this->load->plugin('jquery'); jQuery('#home')->html(date('Y-m-d h:m:s').' - <a id="a" href="#"> Hellow World!!</a>')->css('backgroundColor' , '#ff0000'); // $('#loading').slideDown('fast'); } } // END jquery_php class /* End of file jquery.php */ /* Location: /Applications/XAMPP/xamppfiles/htdocs/riset/application/controllers/jquery.php */ |
Sedangkan untuk viewnya
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>jQuery PHP - Codeigniter library</title>
<meta name="keywords" content="php, ajax, jquery, javascript" />
<meta name="description" content="jQuery PHP library" />
<script src="<?=base_url()?>/jquery-1.3.2.js" type="text/javascript"></script>
<script src="<?=base_url()?>jquery.php.pack.js" type="text/javascript"></script>
<script src="<?=base_url()?>jquery.form.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".ajax").click(function(){
$.php(this.href);
return false;
});
});
</script>
<style>
.output{
border: 1px #000 solid;
backgound-color:#ccc;
}
</style>
</head>
<body>
<script language="JavaScript" type="text/javascript">
formAjax = function () {
$.php(url, $('form#form').formToArray(true));
return false;
}
</script>
<!-- start header -->
<h1>Demo Jquery Client</h1>
<a id="generate" href="<?=site_url('jquery_php/backend')?>" class="ajax">Running</a><br>
<code>
jQuery('#home')->html(date('Y-m-d h:m:s').' - Hellow World!!');
</code>
<br>
<a id="generate" href="<?=site_url('jquery_php/backend2')?>" class="ajax">Running</a><br>
<code>
jQuery('#home')->html(date('Y-m-d h:m:s').' - Hellow World!!')->css('backgroundColor' , '#ff0000');;
</code>
OUTPUT:
<div id="home" class="output"> </div>
</body>
</html> |
Download Jquery-PHP Pluggin
Installasi
1. Extract file di application/plugins/
2. Load pluggin tersebut


tanks master…langsung josss..
nais inpo gan… ini dia yg gw cari2… :thumbup:
“mengitegrasikan syntax jQuery di PHP”
berarti syntax tetep berupa PHP ya bos?
tadinya kukira untuk mengincludekan jquery
ada dokumentasinya?
thanks, nice post
thanks gan..
Aduh ternyata masih banyak yang harus dipelajari, begini nih hasil dari belajar cuma setengah-setengah jadi tanggung, btw step by step using Jquery nya usefull banget, thanks
mangtabs…..
numpang save page gan buat dipelajari hehehe…..
thanks…..
monggo ^^
bro, udah pernah nyoba pake yii framework blom? di yii jg gampang bgt pake jquery. coz ud integrate di dalam packagenya. dulu ane jg pake CI cm skr ganti ke Yii. sambil nunggu CI versi 2
Wah belum ne… bagi2 dong ilmunya..
di extractnya di /system/plugins/ ya ?? soalnya ga ada klo di application/plugins/
Btw apa bedanya klo kita nyimpen folder jquery (beserta isinyee) di luar folder system/
trus kita panggil pake
di extractnya di /system/plugins/ ya ?? soalnya ga ada klo di application/plugins/
Btw apa bedanya klo kita nyimpen folder jquery (beserta isinyee) di luar folder system/
trus kita panggil dari file yang di folder views ??
Kalau pakai php apa nggak malah ribet?
Tergantung.. kalo kita gunain php sebagai generatornya kayaknya makin lebih mempercepat
allow ibnoe… sebelumnya thx bwt infonya gan.. hehehehe…
ada tutorial nya atau materi selengkapnya gak ya?? aq lagi belajar bwt plugin dengan jquery juga… hehehehehehe.. khususnya buat nampilin animasi.. :p
keren mas2 web nya ….