February 28, 2007
I am very excited today, I have finally my chat app ready and working. I have shown my application to all my collegues they throughly enjoyed it.
Soon I will be writing the article about the entire development of this chat application.
I have created three user for the test.
After logging inside you will find a list of User on the left panel, click on the user and start sending messages to them.
So lets have a real feel of the application. Click here to start
February 15, 2007
We are developing a Flex Application with PHP as a middleware. Flex Httpservice component we are using to communicate with the PHP. We have several developers who are doing separate modules. They doing both Flex as well as PHP code. I thought its not proper and need to have a solution where our code will reside on the single url.
How we achieve this?
I thought of developing a architecture which will take a className and methodName from URL and call methods and the supplied object dynamically.
This above url calls getUser method on MyClass Object. I used call_user_method function of PHP which allows me to achieve this.
One trick for this part is also instantiating the object dynamically. I coded like this
static $instance ;
$instance =& new $class;
getObject method accepts className and checks wheather that object exists or not. If object is not set then it creates a object and just return it.
It was a great experience while building something which allows my developers to simplify their code integration. Now every developers is working on their respective classes and using this method.
January 11, 2007
I was working on the application and came accross a situation where I need to replace all character except the numeric ones. My text pattern was something similar to varchar(20). I initial thought to use substr, later moved to explode using “(” token. I suddenly strike is ereg_replace can help me to do this. After writing one line of code I am happy it solve the purpose.
[a-zA-Z()] searches for all the occurences in the string and replace them with supplied character.
I very hardly uses ereg_replace but from now onwards I will encourage myself and others to use ereg_replace.
December 25, 2006
Smarty was one more things which was looking very egly no proper identetion, formatting, comments. No uniformity within the codes. I clean up most of the smarty templates, there are still some more which I will clean up this week.
In PHP, I clean up most part of PHP script, I feel very sorry that I didnt concetrated initially on my code which leads to this.
Some notes I took from this incident
-Always write good code, think before writing the code.
-Analyse it in every aspect, how it can help you in future.
-Is your code is easy to modify in future.
-Can I use the same code in other projects too.
I already started implementing this earlier but not on this project, that was mistake from my side.
But finally I am happy that I clean up many things last week.
December 4, 2006
Its very easy generating xml from php. I have created the following script to achieve this. The same script I used to create simple query analyser using flex.
function getXML($sql=”Default Query”)
$result = mysql_query($sql,$conn);
foreach($row as $key => $value)
getXML(“SELECT * FROM tableName”);
This simple function is very useful in different manner. You can used it when you want to write ajax application, Flex Application.
November 30, 2006
Going through the php document I came across magic constant __LINE__.
-What this contants does?
returns the current Line No. of the file.
-How we can use this constant in development?
I started using this function for most of the debugging purposes. I simply append it with my echo messages. So when I need to go to code, I can directly go the same line.
I more magical constant I used along with __LINE__ is __FILE__. __FILE__ gives the name of the current script file name.
These two functions reduced 20% of my debugging time.
November 27, 2006
Its time for framework, something which offers ready code for most common things we do for every new project. There are numbers of php frameworks available online which allows rapid application development. Also most of the frameworks varies from their config style. Learning curve is again involved in learning these new framework. In many cases I found its quite difficult to customize the frameworks. Every framework has their own style of code which you might not be familiar with.
Then what to do, I thought how about writing my own framework. Some points which basic CRUD model should have are :
-Ready Classes structure
-Easy to understand by any other developer
-Should allow generation of Create, Read, Update and Delete in short CRUD
I have started thinking on the same line. I gone through old codes and started observing the common structure.
-in most of my projects I found all the classe has common structure
-common methods in each class eg. getByID, getAll, addUpdate
-inclusion of file is of same pattern
-most of the php code were common.
After identifying all these points, I started buidling my own framework. You believe me or not, my very basic framework was ready in just 2 hours.
I enjoyed building my own framework.
I will share my experience of building it next time.