All posts by Arvind Kumar

Customizing mysql query of a bound model

I had a hasAndBelongsToMany binding in my Charity Model as i normally would need all the “Causes” available along with Charity information and vice-versa. At one place i needed a specific number of “Causes” picked randomly from the database table. To make this work i had to add following two lines just before the $this->Charity->find call in my controller action:


and i was done.

Does someone has a better solution? Please suggest.

Creating Ajax form in Cakephp (with Prototype.js)

(If you are using jQuery with cakephp you may want to view this article, Creating Ajax form in Cakephp using jQuery )

With the help of prototype/JavaScript we can build really cool and fully functional ajax form in CakePHP really fast.

I have been using the ajax forms in CakePHP for a long time now but in the view of continuous development work always on at CakePHP framework development community i have had to alter ways to write the same code. So here is the latest one. Continue reading

When Firebug made life easier

It’s been around three years now i have been using the Firebug. This great tool provides a web developer an easy way to look at and inspect the source code of a web page. You can view and experiment with each and every part of your web page and related DOM elements, inline or linked CSS, JavaScript and not to say the entire page content. Continue reading

Clear template cache in x-cart

Have you been making changing into a smarty template file (within x-cart and perhaps independently as well) for long and the changes would not come up at all? Who could tell better how frustrating this can be!

The simplest and most effective way to clear template cache in x-cart is to call cleanup.php file which is placed at the root directory of x-cart installation. So if your installation is inside public_html directory (have nothing to do with directory actually) and your website address is just call and all your template cache will be cleared with a message something like this:

The compiled templates cache (“templates_c” directory) has been cleaned up.

(Thanks to Steve for his post)

How to position a pop up element on mouse position coordinates with jquery

Here is a simple yet useful trick to position a tooltip (a div element etc) near the mouse click or pointer position using jQuery. In the example here, we have a tool tip (div) with id “tooltip”, a href tag, on clicking which the pop up is positioned and a snippet of code to place anywhere on the page. Obviousaly this small function can be used to return mouse event coordinates by makeing slightest changes.

I have not tested this code jquery version prior to 1.3.2.

So, here is the javascript code:

$(document).ready(function()  {
    var x = e.pageX;
    var y = e.pageY;
    alert(x +', '+ y);
    $("#tooltip").css({"top":y, "left":x, "position":"absolute"});

The code line below is used to stop click event when action is already over:


And href and div tag html code:


Once there was a man who lived in a forest. He ate in the forest and slept in the forest. He was very happy living in the forest. At last he died in the forest. No one knows why the man lived in the forest. I know this is not a happy story. The end!