Free Android CakePHP GMaps Articles by Bali Web Design

July 31, 2009

Forcing inner join on belongTo and hasOne

Filed under: php — Tags: — admin @ 2:13 am

By default, belongsTo and hasOne using LEFT JOIN relation between parent and child table or model. We can forcing the relationship to use either INNER JOIN or LEFT JOIN based on our need. Cakephp has add new option when binding model, name type: value is LEFT or INNER.

For example we have parent table Author and hasOne Post, we can set INNER JOIN relation by default on model class or in controller using bindModel. In this example the hasOne relation set on model class

<?php
class Author extends AppModel {
var $name = ‘Author’;
var $hasOne = array(’Post’=>array(’type’=>’INNER’));
}
?>

and running on controller

$this->Author->find(‘all’);

cakephp will generate query for author table.

SELECT `Author`.`id`, `Author`.`name`, `Post`.`id`, `Post`.`post_id`, `Post`.`title` FROM `authors` AS `Author` INNER JOIN `posts` AS `Post` ON (`Post`.`post_id` = `Author`.`id`) WHERE 1 = 1

July 29, 2009

Find a data in mysql Array field

Filed under: mysql,query tips — admin @ 1:01 am

I want to show you a situation that probably happen to you when build a mysql query. The situation can be vary but basically same condition. For example we have places table to store all beautiful places around the world. And a categories table to classify our places data. The rule is a place can be put on one or some categories. To achieve this function we just add a field into places table that save category id list.

So places table will have id, name, categories fields. and categories table have id, name. We want to save category list into categories field on places table. The data will look like this ‘2,3,4,5,6,7,8’. A question will come to your mind about how to grab or find a matching id inside this categories, for example we want to show all place with category id 5.

We cannot use LIKE in this example because it cannot match perfectly on many digit number. So i found a solution that easy to do. The query to find all data inside mysql Array field is

SELECT * FROM places WHERE FIND_IN_SET(5, categories)

Another solution is by adding new table to save category list for place. But my solution look nice, right?

July 23, 2009

How to install eclipse for android on windows?

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

You can use any text editor to write a java code for android, and then compile using JDK tools. Create android package (APK) using android sdk tools and then install and run application on emulator. But we need a tool to automatic all android development process. One android IDE that commonly used by android developer is eclipse. Using eclipse you can have an integrated development environment for android through Android plugin, such as

  • write or code java source for android application
  • good overview for your project inside project manager
  • user friendly interface to create new android project
  • compile and debugging is as easy as desktop application development
  • nice java source code editor with high text editing functionality for developer
  • setting emulator also easy with good overview using DDMS perspective
  • run android application inside emulator with simple click

There are many more advantage using eclipse as your IDE for android. Believe me it makes you enjoy coding android with their nice interface and automatic process.

(more…)

How to install android sdk on windows?

Filed under: android,java — admin @ 10:22 pm

For whom that doesn’t know yet the android, it is a new platform that basically run on gphone mobile device. GPhone stand for Google Phone, i think google want to spread their business to mobile device technology. But android is not for gphone only, at least nokia will have android on their device in future. So for developer it is a good market to make an application run on android platform. Best thing is android give developer a software development kit (SDK) that based on java programming language. And this SDK is open to all developer and has big community. This article is about installing android sdk on your windows machine.

First of all you need a java library installed on your machine. It can be a JRE or JDK, but i suggest you to install JDK as we want to develop a java application on our machine.

(more…)

July 14, 2009

Why does findViewById return null?

Filed under: android,java — admin @ 12:10 am

I have been confusing about this problem when doing a project using google map. I believe some of you have this problem also. The problem is simple about a findViewById function on Activity or View always returning Null value. I have the following code on my layout

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>

<com.google.android.maps.MapView
android:id=”@+id/mapView”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:enabled=”true”
android:clickable=”true”
android:apiKey=”0QGdlm3NNz0KF5zSUTn5FvObCU2EUn7Dim25Sjw”
/>

<Button id=”@+id/btnViewPOI”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentBottom=”true”
android:layout_alignParentRight=”true”
android:visibility=”visible”
android:text=”List” />

</RelativeLayout>

(more…)

July 7, 2009

How to change cakephp layout?

Filed under: php — Tags: — admin @ 3:30 am

The cakephp concept is MVC, Model-View-Controller. This three part will divide the area for database, business logic and design part. MVC give a good system to make a clean code for designer, database analyst and programmer. Design work will not interfere the business logic work, cakephp try to limit this thing.

A layout or html output is construct inside main layout and view for each actions. Main layout is a basic layout for your website. We can have some layout for different output type such as html, xml, rss, or etc. For each type we can have different layout as needed. For example registration page will have different layout with homepage.

By default cakephp use all layouts in folder cake\libs\view\layouts if you are not define your layout. You can override cakephp default layout by create ctp file in folder app/views/layouts. The default layout named as default.ctp. How to change this cakephp layout for certain controller action?

Simple create new ctp file inside app/views/layouts, for example mylayout.ctp. And then inside action function on controller put this code

$this->layout = ‘mylayout’;

or you can set folder path for the layout, for example we have layout file saved on app/views/layouts/xml/mylayout.ctp. you can set the path using this code

$this->layoutPath = ‘xml’;

so the complete code for changing the layout is

$this->layoutPath = ‘xml’;
$this->layout = ‘mylayout’;

Create RSS using cakephp

Filed under: php — Tags: — admin @ 2:21 am

It is easy to add RSS into your website using cakephp. Cakephp has a built in library to code or create a RSS output to your visitor. For you that doesn’t know yet RSS, it is a web 3.0 capability to communicate between two website about new update on one website. Its stand for Really Simple Syndication. The purpose is  to give a standard output about new change on your website. For example a blog can have RSS to publish their latest post or article.

i will explain a method to add RSS capability into your cakephp website. In this example we have posts controller for our blog post and we want to create RSS for post table. The rss url will look like this

http://www.yoursite.com/posts/rss or change routing for http://www.yoursite.com/rss into posts controller and rss action.

(more…)

SQL BETWEEN Syntax in Cakephp

Filed under: php — Tags: — admin @ 1:50 am

This article is telling you a code to implement BETWEEN Sql sintak for sql conditions when using cakephp framework. For example we have a table name ‘posts’ and field ‘id’, and then we want to query like this

SELECT * FROM posts WHERE id BETWEEN 1 AND 10

The syntax for above query can be constructed using this cakephp syntax

$this->Post->find(’all’, array(’conditions’=>array(’Post.id BETWEEN ? AND ?’ => array(1, 10))));

I think this syntax is the easiest one to create SQL BETWEEN sintak using cakephp