Feed items

Developing Ajax based web application using CakePHP

One of the challenges in developing ajax application using CakePHP is to figure out how to load ajax view (interface) for first time and request only data (json or XML) in subsequent ajax calls. Luckily, with CakePHP this is simple and you really don’t need to write many different functions. The trick is to use ParseExtension and RequestHandler. You can read more about ParseExtension and requestHandler in CakePHP cookbook (here are links ParseExtension and requestHandler)

CakePHP – using associationForeignKey with belongsTo

While defnining “belongsTo” association in CakePHP 1.2, there are five keys that you can use (to read more about association or belongsTo, checkout this page) . The five keys are className, foreignKey, conditions, fields, counterCache. In general, if you have followed CakePHP conventions, you wont need any other key. However, today I stumbled across a situation where the database was not structured according to CakePHP conventions. As a result, the belongsTo query that CakePHP was generating was not coming out right.
Consider a scenario where a “users” table belongsTo “loctions” table and the two tables are defined as shown below:
1. Users {id, username, passwd, zipcode}
2. locations {id, zipcode, city, zipcode}

Integrating CakePHP and ExtJS: A complete guide

I have moved my blog.

Migrating from OthAuth to CakePHP Auth

This post lists down steps for migrating from OthAuth component to CakePHP’s inbuild Authentication component (Auth Component).
Note about using these migration steps: I used OthAuth mainly for authentication purposes i.e. mainly for verifying a username and password. I never got involved with complex authorization. So, these steps are only applicable if you are using Auth component withouth ACL.

1. In AppController, comment out all the code pertaining to OthAuth component and  add a beforeFilter function, as shown below

function beforeFilter()
//Change hashing function to md5

Dummy’s guide for converting character set of a web application

When developing a web application, one has to be careful about the “character encoding”. There are many options such as latin1, utf8, etc, and the best character encoding depends on the language that your targeted audience use for writing. Since most  web applications are required to handle all types of languages and, thus, are required to handle all different types of characters such as í, é, á. The best way to handle all these various characters is to use UTF8 encoding.
Now the question is where to set UTF8 character encoding. And the short answer is “everywhere”:
          1) at the database level,
          2) at the interface/connection between database and client level (PHP), and
          3) at the data display level (HTML).

Below are the steps that I took to convert Memento from latin1 to UTF8 character encoding

Enhanced Caching of Views in CakePHP 1.2

Image borrowed from James Fee’s blog
It’s good to see that CakePHP developers worked on making Caching mechanism more effective and usable. In CakePHP, you can either 1) cache your data in controller or 2) cache your views (whole view or elements). Jiri talks in detail on how to cache data on controller side. So I won’t discuss that here.  Here I am just reporting how the latest version of CakePHP ( pre-beta) solves a bug (or problem) of caching an element for different users.

Making CakePHP controller independent of how parameters are sent

Recently, I felt the need to make my CakePHP based controllers independent of how  parameters are sent. For instance, in Memento, I can handle parameters sent either in traditional way or using CakePHP style or even using the form (see usage below)
       Example (see how owner value is sent differently in the URL below)
           Traditional Way: http://www.findnwrite.com/memento/articles_users/library/?owner=2  
           CakePHP way: http://findnwrite.com/memento/articles_users/library/owner:2  

CakePHP Tricks for manipulating URL in the view

Note: This blog is now over here
This week, I learnt many new tricks in CakePHP. Below are some of them
1. Get current URL in the view (Thanks to Grant Cox for this one) :
Use  Router::url(“”, true) to get current URL in the view. The second boolean parameter tells whether the path should be absolute or relative. Ideally Router::url(“”, true) should return an absolute URL of the current view, but it always returns the relative URL. So the hack to get the absolute URL is
$absolute_url  = FULL_BASE_URL + Router::url(“”, false);
if you use Router::url(“/”, true), it will return absolute url to your base web directory and this works as desired :p