Free Android CakePHP GMaps Articles by Bali Web Design

Google

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 http://www.balistupa.com/blog, 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 http://www.balistupa.com/app/webroot/blog/ not to http://www.balistupa.com/blog/. This is not look good for visitor and also for seo. Because the folder structure is to deep.

(more…)

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′)));

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 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

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

September 24, 2008

Google Maps Mania

Filed under: google maps — Tags: — admin @ 10:25 pm

As become familiar with Google Map API coding, i would like to announce me as Google Maps Mania. We knew that since 2005, Google has release a beta version of Google Maps Service in February 2008 through its Labs Incubator. And on June 2005 Google Map API is released to all programmer around the world.

Using this great API, Google allowing programmer to create thousand of application using their Google Maps Services. At my first glance, the ability to toggle between street map and satellite view is amazing. For some country we can see a road map also.

Since 2007, i were involving with 2 Probypro’s Project based on Google Maps API. One is known as Pop portal project and the other is Tourismausportal project.

Being involving with this 2 project is sharp my skill on Google Maps API. And because i am doing core code for this two application make me know that Google Maps API is great for building Map Application. And it is free for all.

So on next day i will post many article focus on Google Map API. You can find all topics related to Google Maps coding under google maps category

April 13, 2008

How to find current URL using php?

Filed under: php, php-tips-basic — Tags: — admin @ 9:56 am

Sometimes we need to find current URL for processing on script. URL is construct by three component :

  1. Domain name : www.domain.com
  2. Script name : index.php
  3. Query string : parameter on url, example component=member&task=edit

Using $_SERVER variable we can get this all information and construct it to get full URL. We need to retrieve value ‘HTTP_HOST’, ‘SCRIPT_NAME’ and ‘QUERY_STRING’ on $_SERVER array. Here is the code :

$url = “http://” . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . “?” . $_SERVER['QUERY_STRING'];

this script produce complete current url, if you don’t need host to be included you can just use values from $_SERVER['REQUEST_URI'];