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

June 22, 2009

How to check nofollow link on firefox?

Filed under: css,html — Tags: — admin @ 12:36 am

As a SEO master, sometime we need to add backlink from another sites to our sites. More backlink can give good SEO credit to your website, of course best if the backlinks come from high page ranking site and have related content with our website.

There are many free resources to get free backlink to you, for example social networking site, social bookmarking site, or blog comments. Important to check if the link give to you is a dofollow link type. Only dofollow link type can give SEO credit to your websites. This rule is apply at least to Google Search Engine.

How to check if the sites can give you dofollow link to your websites? simple way is by view page source on the websites and check if the link contain rel=”nofollow” attribute. If it has then that website cannot give you a backlink. Another thing is to use a plugin or tool to check if the website using dofollow or nofollow link. But until this time, i don’t find a good tool for that. I am to lazy also to view page source and read through the html code if the link using nofollow or not.

I need an easy way to check the link, that means when loading, the browser must give a sign on nofollow link. I believe this way is more faster to check about it. I found a simple solution for firefox. The idea is to add user define style to firefox. So everytime we load a web page, that css will override all style defined.

To do it, please create or edit a file named userContent.css in C:\Documents and Settings\{Your User}\Application Data\Mozilla\Firefox\Profiles\{random string}\chrome. And then add this line into last line :

a[rel*=”nofollow”] {
border: 1px dashed black;
background: #FFFF99;
}

And then save it. Please restart firefox to load the setting. Now, if you open a website with nofollow link, you will get a link with dashed border and #FFFF99 background color.

The first link is a nofollow link, and second link is dofollow link.

May 14, 2009

Controlling loop using break and continue with php sample

Filed under: php,php-tips-basic — admin @ 10:34 pm

Probably this article is not talk about high level programming, but as programmer you will need to learn the basic of looping and how to control the loop. We will often use loop to iterate a code or an array to search or doing something. The traditional sintak of loop schema is while, do while, for or for each. This sintak is available on most programming languages.

In this article i will give loop example using php languages. PHP is the most web programming language that commonly use over the internet and web server. We use loop to do similar thing sequently, we call it also iterating a code or commonly iterating an array value.

For example to print number 1 until 10, we can use for statement.

for($i = 1; $i <= 10; $i++) echo $i;

Inside a loop we can put another loop or called as nested loop. When our application is become complicated, nested loop is often use. We commonly use nested loop to do a recursive iteration.

We need to control a loop, deciding the start point and the end point is a must. Without controlling it, you probably create never ending loop. for example this loop

$i = 0;
while($i <= 10){
//
}

To control a loop you need to mention start point and end point. Start point would be initial value for loop condition so the loop can start, for example $i= 0;. Next thing to remember is the end point. In this case $i > 10. So if true condition still valid, the loop still run.

Another control for loop is continue and break statement. Continue statement use to continue the loop to next iteration. In this case all code after break will not executed. I give you an example about how to print only odd number in range 1 until 10.

<?php
for($i = 1; $i <= 10; $i++){
if($i % 2 == 0) continue;
echo $i;
}
?>

On the other hand, break statement used for stoping current loop. For example we want to stop the loop when $total_number > 100;

<?php
$total = 0;
$i = 1;
while(true){
$total += $i;
if($total > 100) break;
$i++;
}
echo $total;
?>

When doing nested loop, we can set number of level that we want to break the nested loop. For example we want to break all loop from second loop, we can use break 2; means we break current loop and outhermost loop.

<?php
$a[0][0] = “a”;
$a[0][1] = “b”;
$a[1][0] = “y”;
$a[1][1] = “z”;
foreach ($a as $v1) {
foreach ($v1 as $v2) {
if($v2 == ‘y’) break 2;
echo “$v2\n”;
}
}
?>

This loop will break when $v2 == ‘y’.

I hope this simple tips can help you understanding on how to control a loop inside your application code. Keep improving your php skill by learning more. Good luck

« Older PostsNewer Posts »