Category Archives: web development

Write human readable debug info!

It’s a common begginer’s developer mistake to write some fullish debug info like “i’m in the IF”, or even worse – “test”. Of course when debugging you don’t get any aditional information. You know only that – you’re in the IF statement!? What a good news! That doesn’t tell you much, isn’t it?

Another bad way to debug is to dump only ids from some database table or loop index. At least write something before that, something like:

alert('on the: ' + index + ' happened something!');

that gives you more and can improve your work so much.

Array hint in JavaScript

new vs []

There are two ways to make new instance of a JavaScript array. As the previous sentence says one of them is by using the new operator. Actually even if you’re not familiar with JavaScript you’ve probably heart something about “new” from some other programming language, as it is very common to appear in almost every one. The way you make new instance is simply by:

var arr = new Array();

That seems pretty natural. The other way to make new instance, probably with some basic initialization is by using:

var arr = [];
// or if you'd like to put some predefined
// values into the array
// on init time
var arr = ['val1','val2'];

The reason I write this post is because as it seems the second way to instantiate an array in JavaScript is faster. That even if it seems funny is really important, because in modern, cool sites there’s a lot of JavaScript and probably there are thousands of “new Array()”‘s which replaced by the simple “arr = []” may result in faster and more user fiendly site!

So use:

var arr = [];

OBJECT & … forget about EMBED tag!

Actually most of us think about OBJECT and EMBED tags as inseparate pair. The reality is different. In fact you don’t need to use the EMBED tag.

Only by using the OBJECT tag you ensure it will be interpreted correctly by every browser.

As you may know, the EMBED tag is supported by Gecko and WebKit, but not by IE. On the other side the OBJECT tag is supported by every one.

Why than the most common usage is with OBJECT and EMBED? That’s by me because of misunderstanding of the semantics of those two!

Toggle the visibility with jQuery

When it comes to quick JavaScriopt effects one of the most common is to hide and show different elements in the DOM. That occurs in almost every site. If there’s a dynamic menu, there’s for sure attached mouse event that shows/hides some sub menus and so on.

Of course you can achieve this in both jQuery and pure JavaScript approaches. If you use JS it’s something like that;

document.getElementById('element_id').style.display = 'block';
document.getElementById('element_id').style.display = 'none';

where the first row shows how to show an element, and the second one how to hide it in turn. Continue reading Toggle the visibility with jQuery →

Redirecting with Zend Framework

Many of the web applications need to be redirected to some given URI sooner or later. In that scenario like redirecting to the profile page after login, which is very common to almost every app, you need to change the URI of the browser after the login form is validated. You can make this by simply using the built in header function in PHP. In other terms the most popular method to redirect in Zend Framework, don’t know why, but this is the _forward method of the controller actions:

$this->_forward('action-name');

The problem here is that thus you get to the given action name, or controller/action but the URI of the browser stays as it is from the caller action.

If you’d like to redirect, like the header function will do it you should use the following construction:

$this->_helper->redirector->gotoRoute(array(
   'controller'=> 'contrlname',
   'action' =>'actionname'));