SM Team blog

How to - Learn many things about php, flex, webservices and more programming language.

Comming soon - Create your websites faster by adding some of our dynamic content in less than 10 minutes.

There is an interesting new web service at http://letsgodynamic.com named D-Modules.

D-Modules provide interactive dynamic modules that can be embedded in your website simply by copying few lines of code. No technical knowledge is required to integrate our modules.

Rate this:
2.5

Twitter with gmail

For the person who likes to use twitter, I discovered a the new gadget named twittergadget

TwitterGadget is a new tool that essentially allows you to have all of the main features of Twitter inside of Gmail as a Google Gadget. It lets you view your public timeline – which auto-refreshes up to every 3 minutes – view replies and direct messages, and post updates.

To access it, you’ll first need to enable custom gadgets in Gmail, which can be done from the Labs page under Settings. From there, you just insert the URL via the news “Gadgets” link you’ll have under Settings - http://www.twittergadget.com/gadget_gmail.xml - at which point you’ll be prompted for your Twitter login.

Rate this:
2.5

AJAX - How to transfer large data using http get

Recently, I need to use a tag script to with cross domain AJAX in my project. But I discovered a important problem, the problem is we cannot transfer large data with this method. Why? Because GET limit the size of the data depend on which browser is using.  But, I found a method used by DOJO toolkit at http://dojotoolkit.org/node/87. It use a IFRAME and fragmented identifier.

Here is the explanation

  • Define a JavaScript object that implements the XHR interface (a Facade).
  • Use that object instead of an actual XHR object.
  • For the Facade’s send() method, serialize the request headers, method, URL and data.
  • The browser places a limit on the size of a document’s URL, so the Client document breaks this serialized data into a set of fragment identifiers that will fit under the URL limit.
  • The Client document sends each fragment identifier to the Server document. The Server document sends an acknowledgement back to the Client, and the Client sends the next fragment identifier, until all are sent.
  • The Server document assembles the fragment identifier parts into the original serialized data, unpacks it into an object, then uses a real XHR object (now on the Server’s domain) to do the final API service call.
  • The Server document then serializes the XHR response, and sends it back to the Client using fragment identifier segments.
  • The Client unpacks the serialized response, and sets the appropriate values on the XHR Facade.

If you have the same problem as me, USE IT!

Rate this:
2.5

XML data with Smarty template engine

It’s easy to use XML with smarty. The first thing to do is to create a php file, call smarty lib and the xml file

Here is the XML file

<RESPONSE>
<SESSION_INFO/>

<RESULTS>

<LIST_PHTO>

<PHTO id=”PHTOc4c7c61ad3d302b6009b262fd12e9d47″>
<ID>PHTOc4c7c61ad3d302b6009b262fd12e9d47</ID>
<DATE_CREATED>2008-10-01</DATE_CREATED>
<DATE_LAST_UPDATED>2008-10-08</DATE_LAST_UPDATED>
<ACTIVE>1</ACTIVE>
<RELATED_SCLNT/>
<PHTO_RELATED_CNEWS/>
<PHTO_TITLE>Pepper</PHTO_TITLE>
<PHTO_DESC>Pepper qui est entrain de se rouler</PHTO_DESC>
<PHTO_WIDTH>0</PHTO_WIDTH>
<PHTO_HEIGHT>0</PHTO_HEIGHT>
<PHTO_FORMAT/>
<PHTO_RELATED_SFILE>SFILEd98dccd56363d534212b6562bf9f2316</PHTO_RELATED_SFILE>
<CHILD/>
</PHTO>

<PHTO id=”PHTO113abeda60b63ac1942b6f0167dedfdf”>
<ID>PHTO113abeda60b63ac1942b6f0167dedfdf</ID>
<DATE_CREATED>2008-10-01</DATE_CREATED>
<DATE_LAST_UPDATED>2008-10-08</DATE_LAST_UPDATED>
<ACTIVE>1</ACTIVE>
<RELATED_SCLNT/>
<PHTO_RELATED_CNEWS/>
<PHTO_TITLE>Whisky</PHTO_TITLE>
<PHTO_DESC>Whisky qui regarde on ne sait pas ou?!?!</PHTO_DESC>
<PHTO_WIDTH>0</PHTO_WIDTH>
<PHTO_HEIGHT>0</PHTO_HEIGHT>
<PHTO_FORMAT/>
<PHTO_RELATED_SFILE>SFILEb657cdc42676b9e5a2e29d4fcfca59dd</PHTO_RELATED_SFILE>
<CHILD/>
</PHTO>
</LIST_PHTO>
</RESULTS>

<DEBUG>
<MESSAGE>(DATABASE.QUERY) SELECT * FROM `photo`  </MESSAGE>
</DEBUG>
</RESPONSE>

Here is the photo.php which get the xml file and assign it to a smarty var

<?php
require_once(’libs_smarty/Smarty.class.php’);

$oSmarty = new Smarty();
$oSmarty->template_dir = “templates”;

$oXmlFileURL = simplexml_load_file(”http://mywebsite.com/myxmlfile.xml”);

$ListPhoto = $oXmlFileURL->RESULTS->LIST_PHTO->PHTO;

$oSmarty->assign(’smarty_xml_file’, $ListPhoto);

$Output = $oSmarty->display(’photo.tpl’);

Here what I have in my template file

{foreach from=$smarty_xml_file item=PHTO}
<div align=”center” style=”border-top: 1px solid” width=”200″>
<h4>{$PHTO->PHTO_TITLE}</h4>
<img src=”http://mywebsite/{$PHTO->PHTO_RELATED_SFILE->LIST_SFILE->SFILE->URL}” width=”200″/>
<p>{$PHTO->PHTO_DESC}</p>
</div>
<br>
{/foreach}

If you have question ask me! :)

Rate this:
2.5

How to create multilingue application with Flex 3.0

I will explain how to create an multilingue application with RessourceBundle class. There is 3 steps to do multilingue application

Summary
  1. Create your properties files
  2. Create folders to insert properties files
  3. Change your flex compiler configuration to insert path to the properties files
  4. Insert some code lines in your application

Detail

1. Create your properties files

To translate your application you hate to create some properties files. In those files you have to insert you label or text message that you want to change in your app.

Exemple:

I created 2 files.

The first one is login_EN.properties.

Here what I put in the file…

pLoginTitle = Connection…
pLoginUsername = Username
pLoginPassword = Password

pLoginTitle is for the label title on the login window and …

The seconde one is login_FR.properties

Here what I put in the file…

pLoginTitle = Connexion…
pLoginUsername = Utilisateur
pLoginPassword = Mot de passe

2. Create folders to insert properties files

When you have created your properties files you hate to put it in a locales folder that you will create from your project folder.

Exemple:

[PROJECT]/locales/multi

and put your properties files in the foder

3. Change your flex compiler configuration to insert path to the properties files

Change your additional compiler arguments in your project properties configuration to “-locale en_US -sp ../locales/multi”

4. Insert some code lines in your application

In your flex code you have to use RessourceBunlde class used for localization.

Exemple:

import mx.resources.ResourceBundle;

ResourceBundle(”login_FR”)]
private var rb_fr:ResourceBundle;
[ResourceBundle("login_EN")]
private var rb_en:ResourceBundle;

private var langue:String;

[Bindable(event="langChange")]
private function geti18nText(key:String):String{
return this["rb_"+langue].getString(key);
}

private function ChangeLangue():void {

if (btnLangue.label == “English version”) {
this.langue = “en”;
btnLangue.label = “Version francaise”;
} else {
this.langue = “fr”;
btnLangue.label = “English version”;
}

var e:Event = new Event(”langChange”);
this.dispatchEvent(e);

}

I created a button in the design form and insert ChangeLangue() in the onclick event and you will get an multilinge application with flex. I showed you a very simple exemple of what you can do.

Rate this:
2.5

PHP - Design Pattern - Singleton

Design pattern are extremely useful in PHP. Here is how you implement a singleton design pattern in PHP.

First, the problem! Do you want a object who is not related to other object, who is unique and who can be retrieve by any other object in the system? If yes, the singleton will become your best friend.

The singleton is the most simple design pattern ever made. It give you a solution to have independent object in your system that every others object can access.

So here is an example of code :

class SimpleSingleton {
/**
* Instance of himself
*/
private static $instance = null;

/**
* Method to call this object
* SimpleSingleton::getInstance();
*/
public static function getInstance(){
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}

/**
* Private constructor of the class
*/
private function __construct(){
//Instruction
}

/**
* A simple Method
*/
public function method1(){
//Instruction
}
}

How it is working? Simple! The singleton object own the only instance of himself. So, if an other object want to talk to the singleton, he just have to ask him to send back is instance.

Here is how you call the singleton :

$instance = SimpleSingleton .getInstance();

Now, to call a method :

$instance->method1();

As you can see, the singleton deisgn pattern is really simple and extremely useful so use them anytime you need them.

Rate this:
2.4 (1 person)

Deep Linking

“Deep Linking” is a term used by web developers to describe support for URL-based navigation in applications that are not a traditional hierarchy of HTML pages.

By default, Flex (and AJAX) applications don’t work this way. Your Flex application is accessible via one URL and you change what the user sees within the Flex application instead of switching to a new URL. In fact, switching to a new URL closes your application and, while it could open another Flex application at the new URL, you would lose the ability to make nice transitions between the visual states of your application and make it harder to share data between the application states, so typically you want to work within one URL, but then you don’t have the navigation features users expect such as back button, bookmarking, etc.

Deep Linking allows the URL to represent different “places” in a Flex application without closing the application as you change the URL. This is accomplished by using real or faked named anchors (depending on which browser you are using). Named anchors are parameters that follow the “#” in a URL that are normally used to navigate to different places within an HTML page.

Rate this:
2.5