CakePHP – Get Current URL in View

echo Router::url($this->here, true);


echo $this->here;


CakePHP – Sessions

print_r($this -> Session -> read());

$this -> Session -> write("variable", "value");
$this -> Session -> read("variable");

$user_email = $this -> data['User']['email'];
$user       = $this -> User -> find("email = '$user_email'");
$this -> Session -> write('User', $user['User']);

$this -> Session -> read("");

if ($this -> Session -> valid()){
	$this -> Session -> destroy();
	$this -> redirect('/');

CakePHP – Find, FindAll, Find(‘all’), Read

Use Model::read() when you have the ID, ie: you know the record you are referring to. Also read() will populate the Model::$data in a way suitable for Model::save() while find() will simply return the resultset array.

Use find() / findAll() / find(‘all’) to find records.

Both methods should fetch associated models given the correct Model::$recursive value.

Model::read is only a wrapper for Model::find


[CakePHP] Disable Model Queries Caching

Again a simple tip. CakePHP by default, in order to optimize performance, has a query caching system. This is a very cool feature but sometimes it may be self-defeating. For example when you do queries for Unit Testing.

In order to disable query caching, it’s enough to set the model cacheQueries variable to false. Setting it to true will re-enable queries caching.

You can disable it for the whole model “life-time” setting it during “design time”

class Project extends AppModel {
var $name = "Project";
var $customValidate = array("name");
var $cacheQueries = false;

or you can temporarily disable it by calling the $this->Model->cacheQueries=false (use your model instead of “Model”)


Configuring Dreamweaver 8 for Editing .thtml File

I needed Dreamweaver to recognize a new file extension called, “thtml” for CakePHP. Here is how I got Dreamweaver to recognize new code extensions and highlight them correctly:

  1. Edit your Extensions.txt file: C:\\Documents and Settings\\User\\Application Data\\Macromedia\\Dreamweaver 8\\Configuration
  2. Add in the new file extension into its type: HTM,HTML,HTA,HTC,XHTML,THTML:HTML Documents
  3. Now Dreamweaver recognizes the new file types but to get code highlighting you need to edit your MMDocumentTypes.xml file: C:\\Program Files\\Macromedia\\Dreamweaver 8\\Configuration\\DocumentTypes
  4. Add in the new file extension to HTML winfileextension.

Here is the full article by Adobe: Adobe: Changing and adding file extensions recognized by Dreamweaver


PHP-Oracle Binding

I’ve got a problem on  CakePHP-Oracle when doing INSERT/UPDATE operation to a field with large size text.

The error usually  “string literal too long”.

I’ve tried to use binding which works like a charm (at least until now), here’s the example:

$conn = OCILogon(‘username’, ‘password’, ‘databasename’);
$stmt  = ‘INSERT INTO pegawai(pegawaiid, namapegawai, alamat) ‘;
$stmt .= ‘VALUES(:pid, :nama, :alm)’;

$stid = OCIParse($conn, $stmt);

OCIBindByName($stid, “:pid”,   $f_id , 4);
OCIBindByName($stid, “:nama”, $f_name, -1);
OCIBindByName($stid, “:alm”, $f_address, -1);


The number 4 on the binding pid is the numeric digit width.