Free Android CakePHP GMaps Articles by Bali Web Design

October 28, 2010

How to log your website using cakephp

Filed under: cakephp,php — admin @ 7:50 am

Cakephp is a good framework, it is a rapid web development framework for building any type of website. As a framework, cakephp has many built in feature. One of cakephp feature is build in logging system. Developer can easily log their application using cakephp.

Log function that can be accessed through your controller easily. You can save or add new log into error log or debug log, or you can make new log file. All file will be placed inside CAKEPHP_FOLDER/app/tmp/logs folder

default sintax that added to CAKEPHP_FOLDER/app/tmp/logs/error.log

$this->log("error message log");


October 13, 2010

Captcha component for cakephp using

Filed under: cakephp,php — admin @ 8:32 pm

Captcha is a type of challenge-response to ensure that the user is really a person that the response is not generated by computer. We usually find captcha on any form input on a website such us contact us, feedback, registration and etc. The captcha is used to protect our site from spammer.

The popular captcha is recaptcha from website. It is free for use. Their interface or design also really nice to put on your website. You can check their sample in They support both image captcha and audio chaptca.

Since i work with cakephp framework, i need to integrate this captcha into my application. I would like to share my captcha component for you. It is a simple code and easy to integrate. Here are the step (more…)

October 7, 2010

How to set foreignKey for belongsTo cakephp without id

Filed under: cakephp,php — admin @ 2:45 am

Cakephp has a good ways for handling table relationship model using AppModel association structure. It is easy to create and set relation between two or more tables on your database. Cakephp has setting for one to one, one to many, many to many relationship.

I would like to tell you about setting foreignKey for one to many relationship in cakephp that the master table doesn’t have foreignKey id. On your model, the relationship for one to many that set on child table would look like this

	class CurrencyRate extends AppModel {
		var $belongsTo = array('Currency' => array(
			'className' => 'Currency',
			'foreignKey' => 'currency_id',



September 4, 2010

How to redirect wordpress blog url cakephp

Filed under: cakephp,php,wordpress — admin @ 7:15 pm

Cakephp have great routing capability, i was install wordpress blog on my main website root directory. And then i need to move my blog into new folder, i put it on /app/webroot/blog/ because i build new web application on root directory using cakephp.

I use rewriting rule for my wordpress blog. The rule is I want to redirect into I don’t want to loose my blog visitors because the blog posting has good ranking on google.

So i do setting on app/config/routes.php and add this line

Router::connect(‘/:year/:month/:slug’, array(‘controller’ => ‘pages’, ‘action’ => ‘redirect_blog’), array(‘pass’ => array(‘year’, ‘month’, ‘slug’), ‘year’ => ‘[0-9]{4}’, ‘month’ => ‘[0-9]{2}’, ‘slug’ => ‘[A-Za-z0-9-]+’));


August 2, 2010

How to redirect /app/webroot/blog/ into /blog/ WordPress Cakephp

Filed under: cakephp,php,wordpress — admin @ 8:16 pm

At this time, a company website normally should have blog to post some business activity or related activity with website themes. WordPress is the best blog framework (CMS) that i ever used. When i was build web application under my own php framework, i wasn’t worried about integrating wordpress into my website. It would has separated setting with main application.

However, now i am using cakephp framework. And if we need to put file or folder, it need to be put inside app/webroot folder. So if i need to install wordpress blog in, i need to put the blog folder inside /app/webroot/.

The problem is about the url, with standard setting the blog would be redirected to not to This is not look good for visitor and also for seo. Because the folder structure is to deep.


July 21, 2010

Sleep or wait process on javascript thread

Filed under: html,javascript — admin @ 10:10 pm

Actually there is no Thread.sleep method on javascript that work on Threading. Moreover there is no true threading in javascript. So everybody that want to deal with threading need to emulate it. In this article i would like to show you some method that emulate sleep method for waiting on a process. Each of this method has each own disadvantage, so you need to choose which is suitable for your case.

First method is sleep using javascript loop. This is first method that come to my mind when emulate sleep method on javascript. We wait for the process by checking the time in the loop.

function wait(millisecond) {
var date = new Date();
var current_date = null;

do { current_date = new Date(); }
while(current_date-date < millisecond)

// do something
wait(1000); // wait 1000 millisecond
// do something


How to handle user closing browser windows or page using javascript

Filed under: html,javascript — admin @ 12:40 am

Sometime we need to handle or do something when user closing a browser windows or page. Maybe we want to ask user if they really want to close the page or it was a mistake click. This procedure all can be done using javascript.

There are two condition or event that you can intercept before it really happen, first when user close the browser windows and second is when browser windows will be closed without any way to abort it.

For first condition we can handle it using window.onbeforeunload event.

function closeHandler() {
return “Are you sure you want to close this page?”;

window.onbeforeunload = closeHandler;


August 31, 2009

How to print javascript object properties

Filed under: html,javascript — Tags: — admin @ 2:32 am

Sometime we need to print the structure data that return by a function. I was work on a task for google map and need to print object properties of Placemarks object on javascript. I need to analyze what kind of structure data return by geocoding function. The code below is a short function to print object properties in javascript

function isObject(obj) {
return obj.constructor == Object;

function print_object(object, level){
var tab = “”;
if(level > 0){
for(i = 0; i < level; i++) tab += “\t”;
var str = “”;
for(prop in object) {
if(!isObject(object[prop])) str += tab + prop + ” value :” + object[prop] + “\n”;
else str += tab + prop + “\n” + print_object(object[prop], level + 1);
return str;

and how to use this function is really simple approach

address = addresses.Placemark[0];
alert(print_object(address, 0));

in this scenario, i would like to print first placemark object return by geocoding function. Parameter level is use to make nice print view using tab character.

August 19, 2009

How to do GROUP BY HAVING in CakePHP

Filed under: cakephp,php — admin @ 11:23 pm

Before June 2008, there is no clean implementation for GROUP BY. commonly people code with CakePHP will put GROUP BY sintak on conditions, something like this

$this->Product->find(‘all’, array(‘conditions’ => ‘1=1 GROUP BY Product.category_id’));

Now CakePhp have a clean sintak for GROUP BY by new additional paramater on find function. We can use ‘group’ to define GROUP BY on cakephp. For example

$this->Product->find(‘all’, array(‘fields’ => array(‘Product.category_id’, ‘COUNT(Product.hotel_id) as total’), ‘group‘ => array(‘Product.category_id’)));

How if we want to have HAVING sintak on query? i ussually use this solution for new cakephp

$this->Product->find(‘all’, array(‘fields’ => array(‘Product.category_id’, ‘COUNT(Product.hotel_id) as total’), ‘group’ => array(‘Product.category_id HAVING COUNT(Product.hotel_id) > 1′)));

August 2, 2009

Passing data or parameter to another Activity Android

Filed under: android,java — admin @ 11:34 pm

Sometime we need to pass data or parameter to another Activity on Android. Only one activity is active at once. An activity open new activity for result and opened activity need parameter to set their interface or another option based on request. So it is important a system can handle sending and retrieve parameter between two Activity.

To open an activity and wait for a result, we can use this sintax

Intent newIntent = new Intent(this.getApplicationContext(), ActivityClass2.class);
startActivityForResult(newIntent, 0);

ActivityClass2 is the class name of activity that we need to create and then open it from current activity. startActivityForResult is a method to run newActivity. Later we can have the result by add this function on current Activity (more…)

« Older PostsNewer Posts »