Tag Archives: codeigniter

Search Term Library For Codelgniter

Do you want to know how your user came to your website via search engine? User usually go to search engine like google and then type a search term and click link from search result page.  Search term can be used for analytic purpose, or search engine optimization (SEO) method.

First step to catch search term is getting the referrer. If referrer is a search engine, get the  search term, clean it from ‘bad words’ and return the result.  Simple, isn’t it? 🙂

WordPress community have a plugin to do the processes. And then i put some of its code to build library for CodeIgniter. You can download this library here.

Using this library is so simple.

$this->load->library(‘Terms_lib’);
$term = $this->terms_lib->search_term;

Done. 🙂

 

Multiple Argument in CodeIgniter’ s Form Validation Callback

CodeIgniter have a powerful form validation class out of the box. We also can create our validation method using a callback. By default, “callback” just accept 1 argument. I didn’t found in user guide, how to make callback accept more than 1 argument.

But, after doing little googling i found a way to do it. For example:

$val->set_rules('field', 'Field Name', "trim|xss_clean|required|callback__example_callback[{$argument}]")
......

function _example_callback($default_argument, $argument) {

.......

See the bold text. Done. 🙂

Sub Query in CodeIgniter

Few month ago, i posted about sub query in codeigniter here. And today i’ve found another way. It using active record class in codeigniter. For example:

$this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE);
$query = $this->db->get('mytable');

Just put ‘FALSE’ to second parameter in select() function. $this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

So simple. Isn’t it?:D

$this->load->view()

When you are using codeigniter, you will use function $this->load->view to load your ‘view’. In codeigniter user guide, a view is described as simply a web page, or a page fragment, like a header, footer, sidebar, etc. In fact, views can flexibly be embedded within other views (within other views, etc., etc.) if you need this type of hierarchy.

In my last project, some fragment on view is loaded in every page. They are header, footer and sidebar. And the content is dynamic. I don’t want to load views for every page. So i write a function in a library (or you can also extends the controller) to handle loading views for every page.
Continue reading

CodeIgniter Modular Programming

CodeIgniter

CodeIgniter has been my favorite PHP framework for a while. CodeIgniter is simple and very easy to use. CodeIgniter applying MVC ( Model View Controller) concept. How about HMVC ( Hierarchical Model View Controller) ?

With a library from Wire Designz, Modular Extensions, we can make CodeIgniter modular. Modules are groups of component in CodeIgniter for example a controller, model, and view separated from application folder.

Continue reading

Upload Validation dalam Form Validation CodeIgniter

Minggu ini saya mengerjakan website dari Elektronika dan Instrumentasi UGM. Saya membuat sebuah content management system(CMS) sederhana untuk memperbarui konten. Konsepnya adalah dalam sebuah posting, akan ada sebuah judul, ringkasan, teks panjang, dan gambar yang mewakili posting tersebut.

Web tersebut disusun dengan menggunakan framework CodeIgniter. Awalnya saya berencana membuat sebuah librari untuk menangani web ini. Jadi saya tinggal fokus pada librarinya. Termasuk untuk bagian CMS tersebut. Saya pun menggunakan class form validation dari CodeIgniter untuk melakukan validasi input form CMS.

Continue reading

Website Multi Bahasa dengan Code Igniter

Saya dan tim kandangbuaya kali ini kebagian ‘tugas negara’, untuk membuat website resmi Elins UGM yang baru. Sebenarnya dari pihak Prodi hanya menginginkan untuk dibuat satu bahasa saja. Namun saya mengusulkan untuk dibikin multi bahasa. Dan akhirnya dibuat dua bahasa, Indonesia dan English.

Kami coding menggunakan CodeIgniter PHP Framework, dimana CI sudah support untuk internasionalisasi multi bahasa. Nah, bagaimana kita mengaplikasikannya? Gimana sih d3ptzz???