Skip to content →

Category: CakePHP

CakePHP Cookbook updated!

After almost 3 year using the old design, the team decide make a major facelift to the cookbook. They even put local cache function. kudos!

Leave a Comment

CakePHP: Ternary condition

Kalau selalu guna if and else, langkah seterusnya mesti tahu ternary condition. ade alternative lain nak guna dalam CakePHP, contoh:

/* ife in cakePHP */ ife($condition, $true, $false)

jadi, kalau statement ternary tu cam ni:

/* ternary condition */ echo ($x)?'x = true':'x = false';

ble ubah jadi macma ni. mudah sket

/* replace ternary with ife in cakePHP */ echo ife($x, 'x = true', 'x = false');

urm.. dapat?

Leave a Comment

CakePHP: Kenapa layout masih tak tukar?

Kalau malas asik nak declare layout di cakephp, aku akan guna code macam ni.

/* before Render */ function beforeRender() { parent::beforeRender(); $this->layout = 'plugin'; .... }

lepas tu aku nak tukar stail layout, misalnya nak guna layout “ajax”. jadi aku declare macam ni..

/* children */ function children($id = null) { .... $this->layout = 'ajax'; }

tapi tak jadi!? kenape? perasan function beforeRender tu?

/* before filter */
function beforeFilter()
{
parent::beforeFilter();
….
$this->layout = ‘plugin’;
}

baru jadi! sebab beforeRender akan override balik variable sebelum render! sebab tu tak jadi.

One Comment