Archive for July, 2011

Select an open File by using Keyboard in Aptana Studio 3

In order to work much more effective, it is best practice to select other open-files by keyboard.
With Aptana Studio 3 you do this very easy and comfortable 🙂

While the editor have the focus, just press ‘Strg’+’E’ and on the right side of the File-Tabs open a small Filelist.


 
The Focus directly switched to an Filter-Field on the top of these List. So you are able to input the name of the needed file. Is the Filelist filtered down to a few files, just use the Up- and Down-Keys to select the needed File.

An other useful shortcut is ‘STRG’+’PageDown’ to select the right next opened File, or ‘STRG’+’PageUp’ to select the left previous File for editing.

Now, who needs a mouse!? 😉

Generate function completion / autocompleter for Aptana Studio 3 PHP Projects

If you develop large Projects, it is really helpful to get all the available functions over an autocompleter, because you didn’t have to look each function-name and his parameters.
The realization theese function with Aptana Studio 3 is very easy.

 
At first, navigate into ‘Window’ > ‘Preferences’ > ‘Aptana’ > ‘Editors’ > ‘PHP-Libraries’.
Here you can create a new user library by pressing the ‘New user library’ Button.


 
Here enter a name for your library and select the folder where the files are located. In my case i want to create an Function-Autocompleter for the same project (Project: filescope – enterprise resource planning), where in i work. So i select my project-directory.


 
After that, uncheck the checkbox from the new entry and close the preferences.


 
Now you have to add the new library to the Buildpath of your PHP-Project. Take a right click on your Project within the ‘Project Explorer’ and select the Tree-Entry named ‘PHP Buildpath’. If you didn’t have a Tree-Entry named ‘PHP Buildpath’, maybe your project isn’t a PHP-Project. In our case, select the ‘Project Natures’ Entry.


 
Confirm the nature change and you become a PHP-Project.


 
After that you should find the ‘PHP Buildpath’ Entry in your Project preferences. Select these Entry and navigate to the Libraries-Tab. There select the ‘Use project specific settings’ Checkbox, then select your created Library and Apply it.

Finally close the properties window by pressing ok and that’s it. 🙂

 
For a quick test open a PHP-File from your Project, type a few initial-letters from any function and press ‘Strg’+’Space’.. Now you should become a selection-menu where you will find all functions, that are matched to your input.

The Best Firefox Addons for Linux for Web Developers

Here you will find a delicious selection of Firefox Addons for Linux, which every Web Developer should have 😉

Firebug Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.
Download it here
FireQuery FireQuery is a collection of Firebug enhancements for jQuery. Requires Firebug 1.3 or greater.
Download it here
gTranslate With gTranslate you can translate any text in a webpage just by selecting and right-clicking over it. The extension uses the Google translation services to translate the text.
Download it here
Web Developer The Web Developer extension adds various web developer tools to a browser.
Download it here
Clear Cache Clear the cache by pressing a single key.
Download it here
TimeStamp Converter Converts dates and timestamps. Context menu option to convert the selected timestamp into a date. Context menu option to convert the selected date/time (allowed formats) into a timestamp. Human readable output of convesions. Support for GMT conversions.
Download it here
ColorZilla Advanced Eyedropper, ColorPicker, Page Zoomer and other colorful goodies.
With ColorZilla you can get a color reading from any point in your browser, quickly adjust this color and paste it into another program. You can Zoom the page you are viewing and measure distances between any two points on the page. The built-in palette browser allows choosing colors from pre-defined color sets and saving the most used colors in custom palettes. DOM spying features allow getting various information about DOM elements quickly and easily. And there’s more…
Download it here

How to use Namespaces and Sub-Namespaces with PHP 5.3

If you want to implement a huge project, it will be better when you encapsulate your modules and classes into several Namespaces and Sub-Namespaces.

But why should you use namespaces?
Namespaces are very useful, if you have some classes in your project, which have the same name as other global classes or classes from other project spaces. If you have two same named classes in the same space, you will have some problems. It is also very useful, to get your project into a modular and easy-extensible structure.

As Sample, we have a project with the following structure:

As Sample, we have a project with the following structure:

    MyProject

      – Module1
      – Module1
      – Module1

From these, we create a similar directory-structure, like:

/MyProject/.
/MyProject/..
/MyProject/MyProjectClass.class.php
/MyProject/MyProjectClass2.class.php
/MyProject/Module1/.
/MyProject/Module1/..
/MyProject/Module1/Module1Class.class.php
/MyProject/Module2/.
/MyProject/Module2/..
/MyProject/Module2/Module2Class.class.php
/MyProject/Module3/.
/MyProject/Module3/..
/MyProject/Module3/Module3Class.class.php

 
Now you can structure your classes as your Namespaces and find easily your classes.

To define a Namespace in a class-file, the file-contents (as sample for the MyProject.class.php) file must start with:

namespace MyProject;

class MyProjectClass {
	...

 
Attention: Namespace-Files must be started with the Namespace-Definition, otherwise you will get an Fatal error:

Namespace declaration statement has to be the very first statement in the script in

 
The Project-Modules, which are also included in the namespace MyProject, we will encapsulate in a sub-Namespace. Therefore you must define the Sub-Namespace in the Module-Files, like:

namespace MyProject\\Module1;

class Module1 {
	...

 
Now your are able to use the Namespaces in your API-File:

namespace MyProject;
error_reporting(E_ALL);
require_once '../MyProject/include.php';

try {
	
	$MyProjectClass = new MyProjectClass();
	...
	
	$Module1Class = new Module1\\Module1Class();
	...

} 
catch (Exception $e) {
	...

 
If we now consider the namespaces in more detail, there is a similar behavior to a file system.
What we have done?
We switched in the namespace (or as sample directory) MyProject, and could directly access our Classes from these Namespace (here as the directory-sample, the files in the directory). Would we now access a global Class (which were in our directory-sample a file in our root-directory), we just add a backslash before the global Identifer:

throw new \\Exception(...

 
If you want to handle a Class from a Sub-Namespace, you have to add the Namespace-Path (also similar to an Filesystem):

$Module1Class = new Module1\\Module1Class();

 
Notice: I’ve integrate the Namspaces into an existing project. The result were some Errors like:
Fatal error: Class ‘MyProject\\Exception’ not found in..
Because the global Exception-class isn’t anymore found, which are very often used in my sourcecode. For a quick’n’dirty solution, you can do something like that:

namespace MyProject;
class Exception extends \\Execption {
}

 
Thanks of the Namespaces, it doesn’t make a Problem to named the Class also Exception 😉

Notice: The Code-Highlighting WordPress-Plugin i use seems to have a little Bug! In the Single-View of a Post a Backslash must be escaped, but in the List-View not. So, if you find a false double-‘\\’, it is a problem with these Plugin 😉