<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>arif.suparlan.com &#187; codeigniter</title>
	<atom:link href="http://arif.suparlan.com/tag/codeigniter/feed" rel="self" type="application/rss+xml" />
	<link>http://arif.suparlan.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 31 Jan 2012 15:38:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Codeigniter: Pagination Helper dengan URI Associative Array untuk Parameter Tambahan</title>
		<link>http://arif.suparlan.com/2011/11/13/codeigniter-pagination-helper-dengan-uri-associative-array-untuk-parameter-tambahan?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=codeigniter-pagination-helper-dengan-uri-associative-array-untuk-parameter-tambahan</link>
		<comments>http://arif.suparlan.com/2011/11/13/codeigniter-pagination-helper-dengan-uri-associative-array-untuk-parameter-tambahan#comments</comments>
		<pubDate>Sun, 13 Nov 2011 05:01:52 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[Iseng]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[paging]]></category>
		<category><![CDATA[parameter]]></category>
		<category><![CDATA[query string]]></category>
		<category><![CDATA[segmented uri]]></category>
		<category><![CDATA[uri associative array]]></category>

		<guid isPermaLink="false">http://arif.suparlan.com/?p=487</guid>
		<description><![CDATA[Pagination library dari Codeigniter sederhana dan sangat mudah digunakan. Tapi gimana caranya kalau kita mau nambah parameter tambahan lainnya seperti filter atau search di antara paging tersebut? Bisa pake query string! Gimana kalo pake URI bersegmennya CI biar rapi? Ga &#8230; <a href="http://arif.suparlan.com/2011/11/13/codeigniter-pagination-helper-dengan-uri-associative-array-untuk-parameter-tambahan">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://codeigniter.com/user_guide/libraries/pagination.html" target="_blank">Pagination library dari Codeigniter</a> sederhana dan sangat mudah digunakan. Tapi gimana caranya kalau kita mau nambah parameter tambahan lainnya seperti filter atau search di antara paging tersebut? Bisa pake query string! Gimana kalo pake URI bersegmennya CI biar rapi? Ga dibahas di user_guide nya nih. Dan entah kenapa, saya lebih suka menyebutnya &#8220;Paging&#8221;.<span id="more-487"></span></p>
<p>Kita pake fitur <a href="http://codeigniter.com/user_guide/libraries/uri.html" target="_blank">URI dan Associative Array</a>, sudah pernah pake sebelumnya? Gampang, dengan &#8220;uri_to_assoc&#8221; kita bisa dapatkan parameter dalam bentuk array dari uri bersegmen dan &#8220;assoc_to_uri&#8221; untuk sebaliknya. Tinggal pelajari user_guide aja.</p>
<pre>index.php/user/search/name/joe/location/UK/gender/male</pre>
<pre>[array]
 (
 'name' =&gt; 'joe'
 'location' =&gt; 'UK'
 'gender' =&gt; 'male'
 )</pre>
<p>Cobain dulu <a href="http://arif.suparlan.com/demo/paging_assoc/" target="_blank">demonya di sini</a>.</p>
<p>Pertama, buat helper dengan nama paging_assoc_helper.php, trus simpan di folder helper. Bisa <a href="http://arif.suparlan.com/demo/paging_assoc/paging_assoc_helper.php.txt" target="_blank">copas di sini</a>.</p>
<pre>&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed.');

    function paging_assoc($varkey, $assoc_n=3)
    {
        $CI =&amp; get_instance();

        $qs_arr = $CI-&gt;uri-&gt;uri_to_assoc($assoc_n);
        $qs_tmp_arr=array();
        foreach($qs_arr as $key =&gt; $value)
            if ($key!=$varkey) $qs_tmp_arr[$key]=$value;

        foreach($CI-&gt;uri-&gt;segment_array() as $key =&gt; $value)
            if ($value=='p') $assoc_n = $key;

        $offset = (isset($qs_arr[$varkey])) ? $qs_arr[$varkey] : 0;
        $qs_uri = $CI-&gt;uri-&gt;assoc_to_uri($qs_tmp_arr).'/'.$varkey;

        return array(
            'offset' =&gt; $offset,
            'seg' =&gt; $assoc_n+1,
            'uri' =&gt; $qs_uri,
            );
    }</pre>
<p>Kemudian buat sebuah controller, atau untuk ngetes, replace saja welcome.php controller. Jangan lupa load library dan helper yang diperlukan. Cara penggunaannya kira-kira seperti ini:</p>
<pre>        //get paging settings, uri, segments, and offset
        //input param paging variable key, init segment
        $pg_arr = paging_assoc('p', 3);</pre>
<p>Tidak begitu rumit, helper ini sebenarnya hanya untuk mendapatkan URI tambahan, segmen untuk paging yang baru, dan offset untuk LIMIT. Scriptnya sudah dites beberapa kali, tapi tidak menutup ada bug. Silakan kalau ada yang mau diperbaiki.</p>
<pre>    public function index()
    {
        //$this-&gt;load-&gt;view('welcome_message');

        //load db, paging lib, some helpers
        $this-&gt;load-&gt;database();
        $this-&gt;load-&gt;library(array('pagination'));
        $this-&gt;load-&gt;helper(array('url', 'paging_assoc', 'form'));

        //get paging settings, uri, segments, and offset
        //input param paging variable key, init segment
        $pg_arr = paging_assoc('p', 3);
        if (isset($_POST['search']))
            redirect('/welcome/index/s/'.$_POST['search']);

        //other parameters
        $assoc_arr = $this-&gt;uri-&gt;uri_to_assoc(3);
        $s = (isset($assoc_arr['s'])) ? $assoc_arr['s'] : '';

        if ($s) $this-&gt;db-&gt;like('text', $s);
        $query = $this-&gt;db-&gt;get('test2');
        $num_rows = $query-&gt;num_rows();

        $paging['base_url'] = site_url().'/welcome/index/'.$pg_arr['uri'];
        $paging['total_rows'] = $num_rows;
        $paging['uri_segment'] = $pg_arr['seg'];
        $paging['per_page'] = 2;
        $this-&gt;pagination-&gt;initialize($paging);

        echo form_open('');
        echo 'Filter: '.form_input('search', (($s) ? $s : 'a'));
        echo form_submit('mysubmit', 'Submit');
        echo form_close();
        echo $this-&gt;pagination-&gt;create_links().'&lt;br&gt;';

        if ($s) $this-&gt;db-&gt;like('text', $s);
        $this-&gt;db-&gt;limit($paging['per_page'], $pg_arr['offset']);
        $query = $this-&gt;db-&gt;get('test2');

        foreach ($query-&gt;result() as $row)
        {
            echo $row-&gt;id.' '.$row-&gt;text.'&lt;br&gt;';
        }
    }</pre>
<p>Dan ini contoh data MySQL nya;</p>
<pre>CREATE TABLE IF NOT EXISTS `test2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `text` varchar(255) NOT NULL,
  `status` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=37 ;

INSERT INTO `test2` (`id`, `text`, `status`) VALUES
(1, 'croissant', 1),
(2, 'dessert', 0),
(3, 'gummi bears', 1),
(4, 'caramels', 1),
(5, 'candy canes', 0),
(6, 'fruitcake', 1),
(7, 'lollipop', 0),
(8, 'jelly-o macaroon', 1),
(9, 'fruitcake', 1),
(10, 'chocolate bar', 0),
(11, 'sesame snaps', 1),
(12, 'jelly beans', 1),
(13, 'jelly-o', 0),
(14, 'donut', 1),
(15, 'applicake', 0),
(16, 'chupa chups', 1),
(17, 'apple pie', 0),
(18, 'cheesecake', 0),
(19, 'pastry', 1),
(20, 'pudding', 1),
(21, 'marshmallow', 0),
(22, 'cookie', 0),
(23, 'croissant', 1),
(24, 'bonbon', 1),
(25, 'gingerbread', 0),
(26, 'tiramisu', 1),
(27, 'toffee', 0),
(28, 'caramels', 0),
(29, 'halvah', 1),
(30, 'sweet roll macaroon', 0),
(31, 'wafer', 1),
(32, 'brownie', 1),
(33, 'ice cream', 0),
(34, 'sugar plum', 1),
(35, 'jujubes', 0),
(36, 'biscuit', 1);</pre>
<p>Selamat mencoba.</p>
]]></content:encoded>
			<wfw:commentRss>http://arif.suparlan.com/2011/11/13/codeigniter-pagination-helper-dengan-uri-associative-array-untuk-parameter-tambahan/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Codeigniter Helper untuk Modular Extensions-HMVC</title>
		<link>http://arif.suparlan.com/2011/02/20/codeigniter-helper-untuk-modular-extensions-hmvc?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=codeigniter-helper-untuk-modular-extensions-hmvc</link>
		<comments>http://arif.suparlan.com/2011/02/20/codeigniter-helper-untuk-modular-extensions-hmvc#comments</comments>
		<pubDate>Sun, 20 Feb 2011 10:41:00 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[hmvc]]></category>
		<category><![CDATA[matchbox]]></category>
		<category><![CDATA[modular extentions]]></category>

		<guid isPermaLink="false">http://arif.suparlan.com/?p=335</guid>
		<description><![CDATA[Di Codeigniter 1.72 saya menggunakan Matchbox untuk modular extention. Dengan Matchbox, saya bisa mengatur applikasi yang saya buat menjadi komponen-komponen terpisah atau secara modular. Sekarang Codeigniter sudah versi 2, sementara Matchbox sudah tidak pernah disentuh lagi oleh pembuatnya. Akhirnya saya &#8230; <a href="http://arif.suparlan.com/2011/02/20/codeigniter-helper-untuk-modular-extensions-hmvc">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Di Codeigniter 1.72 saya menggunakan <a href="http://codeigniter.com/wiki/Matchbox/" target="_blank">Matchbox</a> untuk modular extention. Dengan Matchbox, saya bisa mengatur applikasi yang saya buat menjadi komponen-komponen terpisah atau secara modular. Sekarang <a href="http://codeigniter.com/" target="_blank">Codeigniter</a> sudah versi 2, sementara Matchbox sudah tidak pernah disentuh lagi oleh pembuatnya. Akhirnya saya pake <a href="http://codeigniter.com/wiki/Modular_Extensions_-_HMVC/">Modular Extensions &#8211; HMVC</a> atau ME-HMVC untuk Codeigniter.<span id="more-335"></span></p>
<p>Di bawah ini adalah helper untuk ME-HMVC, dibuat berdasarkan <a href="http://codeigniter.com/forums/viewthread/82622/" target="_blank">Philip Sturgeon&#8217;s Matchbox helper</a>,  dengan sedikit perubahan minor. Masih kasar, belum ditest semua, untuk catatan saja supaya ga lupa.</p>
<pre>
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed.');

function module_directories() {
    return Modules::$locations;
}

function module_array() {
    $module_arr = array();

    foreach (module_directories() as $key=&gt;$value)
    {
        foreach(glob($key.'*', GLOB_ONLYDIR) as $module)
        {
            array_push($module_arr, array('module'=&gt;basename($module), 'path'=&gt;$key));
        }

    }

    return $module_arr;
}

function is_module($module) {
    if(!$module) return FALSE;
    foreach (module_directories() as $key=&gt;$value)
    {
        if (is_dir($key.basename($module))) {
            return TRUE;
        }
    }

    return FALSE;
}

?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://arif.suparlan.com/2011/02/20/codeigniter-helper-untuk-modular-extensions-hmvc/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resize &amp; Crop Gambar Proporsional di Codeigniter</title>
		<link>http://arif.suparlan.com/2009/09/11/resize-crop-gambar-proporsional-di-codeigniter?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=resize-crop-gambar-proporsional-di-codeigniter</link>
		<comments>http://arif.suparlan.com/2009/09/11/resize-crop-gambar-proporsional-di-codeigniter#comments</comments>
		<pubDate>Fri, 11 Sep 2009 06:38:13 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[crop]]></category>
		<category><![CDATA[gambar]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[maintain_ratio]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[scale]]></category>
		<category><![CDATA[skala]]></category>

		<guid isPermaLink="false">http://arif.suparlan.com/?p=137</guid>
		<description><![CDATA[Beberapa hari yang lalu saya memerlukan sebuah class atau library yang sederhana untuk melakukan upload gambar dan sekaligus menyesuaikan ukuran yang saya mau. Dulu saya pernah buat fungsi yang sama, waktu pertama kali kenal GD-nya PHP. Tapi sudah lupa bentuknya &#8230; <a href="http://arif.suparlan.com/2009/09/11/resize-crop-gambar-proporsional-di-codeigniter">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Beberapa hari yang lalu saya memerlukan sebuah class atau library yang sederhana untuk melakukan upload gambar dan sekaligus menyesuaikan ukuran yang saya mau. Dulu saya pernah buat fungsi yang sama, waktu pertama kali kenal GD-nya PHP. Tapi sudah lupa bentuknya gimana. Yang sekarang saya buat adalah library extension untuk Codeigniter.<span id="more-137"></span></p>
<p>Codeigniter sudah punya library untuk upload, jadi upload tidak perlu dibahas lagi. Codeigniter juga sudah punya class untuk memanipulasi gambar diantaranya untuk melakukan Image Resizing, Thumbnail Creation, Image Cropping, dan lain-lain. Tapi untuk melakukan perubahan ukuran gambar dengan skala yang proporsional dengan ukuran yang spesifik, agak sedikit ada hitung-hitungannya.</p>
<p>Pertama kali, dengan membandingkan rasio ukuran awal dan ukuran yang baru, dapat menentukan menggunakan x atau y untuk menjaga proporsi gambar. Kalau mau meng-crop tepat di tengah-tengah gambar, maka axis x dan y juga ikut dihitung. Kecuali kalau cropnya mau dilakukan dari sebelah kiri-atas, axisnya tinggal diset x=0 &amp; y=0. Lebih jelasnya lihat code-nya (my_image.php).</p>
<pre>&lt;?php
if (!defined('BASEPATH')) exit('No direct script access permitted.');

class My_image
{
	var $CI;
	function My_image()
	{
    //parent::CI_Image_lib();
  }  

	function resize_crop($config, $resize_width=200, $resize_height=200)
	{
    if ($config)
    {
      $CI =&amp; get_instance();

      $CI-&gt;load-&gt;library('image_lib');
      $CI-&gt;load-&gt;library('baseintencoder');

      $img_size = getimagesize($config['source_image']);

      $t_ratio = $resize_width/$resize_height;
      $o_width = $img_size[0];
      $o_height = $img_size[1];
      if ($t_ratio &gt; $o_width/$o_height)
      {
        $config['width'] = $resize_width;
        $config['height'] = round( $resize_width * ($o_height / $o_width));
        $y_axis = round(($config['height']/2) - ($resize_height/2));
        $x_axis = 0;
      }
      else
      {
        $config['width'] = round( $resize_height * ($o_width / $o_height));
        $config['height'] = $resize_height;
        $y_axis = 0;
        $x_axis = round(($config['width']/2) - ($resize_width/2));
      }

      $source_img01 = $config['new_image'];

      $CI-&gt;image_lib-&gt;clear();
      $CI-&gt;image_lib-&gt;initialize($config);
      $CI-&gt;image_lib-&gt;resize();

      $config['image_library'] = 'gd2';
      $config['source_image'] = $source_img01;
      $config['create_thumb'] = false;
      $config['maintain_ratio'] = true;
      $config['width'] = $resize_width;
      $config['height'] = $resize_height;
      $config['y_axis'] = $y_axis ;
      $config['x_axis'] = $x_axis ;

      $CI-&gt;image_lib-&gt;clear();
      $CI-&gt;image_lib-&gt;initialize($config);
      $CI-&gt;image_lib-&gt;crop();

      return $config['new_image'];
    }
  }
}

?&gt;</pre>
<p>Memanggil fungsinya seperti ini:</p>
<pre>$config['image_library'] = 'gd2';
$config['source_image'] = $nama_source_image;
$config['new_image'] = $nama_hasil_image;

$this-&gt;load-&gt;library('my_image');
$this-&gt;my_image-&gt;resize_crop($config, '100', '200');</pre>
<p>Saya termasuk noob di Codeigniter, mohon ma&#8217;af kalau ada yang salah tolong dikoreksi&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://arif.suparlan.com/2009/09/11/resize-crop-gambar-proporsional-di-codeigniter/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

