Posted by Prabir Choudhury on December 2, 2009
|

|
|
|
Ever wanted to test your website in various versions of Internet Explorer?
It is possible to run Internet Explorer in standalone mode without having to over-write previous versions thanks to Joe Maddalone who came up with a way of achieving that in November 2003. Basically, Internet Explorer is run by exploiting a known workaround to DLL hell – which was introduced in Windows 2000 and later versions – called DLL redirection.
More >> |
|
| Book mark this |
|
|
Posted in Development, Web Development | Tagged: cross browser, cross browser platform, IE, Internet explorer, multiple browser, multiple ie, multiple Internet Explorer, web application | Leave a Comment »
Posted by Prabir Choudhury on October 29, 2009
|
What is MVC?
|
|
Model-View-Controller (MVC) is a design pattern. A Design pattern is a code structure that allows for common coding frameworks that simplifies application development and maintenances. This architecture model separates the application into three different logical components.
|
|
MVC and Web application
|
|
We are looking an architectural pattern that can help us to organize web application in several ways. We want the application easier to code, loosely bound and easier to maintain. So, if we see MVC as an architectural pattern in web application then we could separate the whole application into three deferent logical components that we would describe bellow.
|
|
The Model
|
|
The Model is the “M” in MVC. The model is where business logic is stored. Business logic is loosely defined as database connections or connections to data sources, and provides the data to the controller. Our database connection is a simple singleton design pattern and can be called statically from the controller and set in the registry and will provide the reusable class library. So, in this layer we are separating all the code those only deals with business logic.
|
|
The View
|
|
The View, is the V in MVC. The View contains code that relates to presentation and presentation logic such as web design, or templating. It control the look and feel of data and provide facilities to collect the data from the user, like login form. Mostly used technologies are HTML, XHTML, Javascript, CSS.
|
|
The Controller
|
|
The Contoller is the C in MVC. Controller actually join the View and Model layer together and change the styling of the View and method or function of the Model. It would collect the data and request from View and passed it to the Model to generate the response back to the View.
The controller is NOT a Mediator between the view and the model. The controller does not sit in between the model and the view. Both the controller and the view have equal opportunity to access the model. The controller does not copy data values from the model to the view, although it may place values in the model and tell the view that the model has changed
|
|
MVC Layering
|
|
To understand basic MVC pattern we would convert a basic PHP application to an MVC architecture application. We would go step by step and convert into MVC pattern.
Basic PHP programming bellow.
|
|
<?php
//connecting and selecting database
$link =mysql_connect(‘localhost’, ‘myusername’,
‘mypassword’);
$mysql_select_db(’student_db’,$link);
//performing sql query
$result =mysql_query(’select first_name , last_name, address from student’, $link);
?>
<html>
<head>
<title>this the flat PHP script for all students</title>
</head>
<body>
<h1>List of student </h1>
<table>
<tr><th>First name</th><th>Address</th></tr>
<?
#Printing result in HTML
While
($row = myslq_fetch_array($result,MYSQL_ASSOC))
{
echo “<tr>”;
echo “<td>”.$row[first_name].”</td>”;
echo “<td>”.$row[address].”</td>”;
echo “</tr>”;
?>
</table>
<body>
</html>
<?php
//closing database connection
mysql_close($link);
?>
|
|
|
Advantage of above code: Quick to write and fast to executable.
Disadvantage: There is no error checking, Php and html code are mixed, Code is tied to mysql database and System is tightly binded.
This above code could be split into two parts first the pure php code and all the business
logic goes to controller layer and in the second part html code containing template-like PHP syntax is stored in view.php page.
|
|
Step 1
|
|
The controller part , in index.php
<?
//connecting and selecting database
$link =mysql_connect(‘localhost’, ‘myusername’, ‘mypassword’);
$mysql_select_db(’student_db’,$link);
//performing sql query
$result=mysql_query(’select first_name, address from student’, $link);
//filling up the array for the view
$students= array();
While
($row = myslq_fetch_array($result,MYSQL_ASSOC))
{
$students[] = $row;
}
//closing database connection
mysql_close($link);
//requiring the view
require(view.php);
?>
|
|
|
The view part , in view.php
|
|
The viewpart , in view.php
<html>
<head>
<title>this the view in mvc students</title>
</head>
<body>
<h1>List of student </h1>
<table>
<tr><th>Name</th><th>Address</th></tr>
<!–Printing result in HTML–>
<?php
foreach ($students as $student); ?>
<tr>
td><?php echo $first_name; ?> </td>
<td><?php echo $address; ?> </td>
</tr>
<?php endforeach; ?>
</table>
<body>
</html>
|
|
|
A good rule of thumb whether the view is clear enough is that it should contain a minimum amount of PHP code in order to understand by an html designer without PHP knowledge. The most common statements in view are echo, print or if/endif, foreach/endforeach. There should not be PHP code echocing HTML tag.
All the logic is moved to controller layer and contains only PHP script with no HTML inside.
Step 2
ISOLATING THE DATA MANIPULATION
Most of the controller script code is dedicated to data manipulation. But if we need another list of student or paper or classes or attendances, or RSS feed. What If we need all the database quires in one place to avoid code duplication? What if we decided to change the data model name to first_name. what if we want to switch the Mysql to MSSql. If we need to do those changes very easily then we need to put all the data manipulation code to another script called model from controller script.
|
|
The model part, model.php
Function getStudents()
{
//connecting and selecting database
$link =mysql_connect(‘localhost’, ‘myusername’,
‘mypassword’);
$mysql_select_db(’student_db’,
$link);
//performing sql query
$result=mysql_query(’select first_name , address from student’, $link);
//filling up the array for the view
$students= array();
While
($row = myslq_fetch_array($result,MYSQL_ASSOC))
{
$students[] = $row;
}
//closing database connection
mysql_close($link);
//requiring the view
require(view.php);
return $students;
}
|
|
|
Controller index.php script changed to
|
|
Controller index.php script changed to
<?php
//require model
require(model.php);
//retrieving the list of students
$students= getStudents();
//requiring the view
require(view.php);
?>
|
|
|
The controller become easier to read and maintain. It’s sole task is to get data from model and pass it to view. In more complex application, the controller also deals with the request, the user session, the authentication so on. The model script is dedicated to data access and could be organized accordingly. All parameters that doesn’t depends on the data layer (like request parameter) must be given by the controller and not accessed by the model. The model functions could be reuse by another controller.
So the principal of the MVC architecture is to separate the flat PHP code into three different layers, according to its nature. Data logic code is placed within the model, presentation code within the view and application logic within the controller.
Other additional design pattern could make the coding experience even easier. The model , view and controller layers could be subdivided.
Step 3
Database abstraction layer
The model layer could be split into data access layer and data abstraction layer. That way data access function will not use database dependent query statements, But some other functions that will do the quires themselves.
Database abstraction part of the model layer
|
|
function oprn_connection ($localhost, $user, $password)
{
//connecting and selecting database
return mysql_connect($localhost, $user, $password);
}
function close_connection ($link)
{
//closing database connection
mysql_close($link);
}
Function
query_database ($query, $database,$link)
{
mysql_select_db($database,$link);
return mysql_query($query, $link);
}
Function fetch_results($result)
{
return mysql_fetch_array($result);
}
Data access part
function getStudents()
{
//connecting and selecting database
$link =open_connection ($localhost, $myusername,
$mypassword);
//make sql query
$myquery =’select first_name , address from student’;
//performing qurry
$result = query_databa($myquery,’student_db’,$link);
$students = array();
While
($row = myslq_fetch_array($result,MYSQL_ASSOC))
{
$students[] = $row;
}
//close the connection
close_connection($link);
return $students;
} // end function getStudents
|
|
|
Step 4
Separate View elements
|
|
The View elements could get the benefit from some code separation that makes the web application a consistent through out the application as the page header, the graphical layout, body content, global navigation and the footer. Mainly the body content parts reply changes depends on the request. We could separate the view element into ‘layout’ and ‘template’ and ‘logic’ or ‘view’ where ‘layout’ holds the global or group of view elements to the application and the ‘template’ hold the body content part of the application according to the variables reply from the controller and ‘logic’ or ‘view’ layer will help to make the ‘template’ and ‘layout’ work together.
|
|
The template part of the view template.php
|
<h1> List of student </h1>
<table>
<tr><th>Name</th><th>Title</th></tr>
// Printing result in HTML
<?php foreach ($students as $student); ?>
<tr>
<td> <?php echo $name; ?> </td>
<td> <?php echo $title; ?> </td>
</tr>
<?php endforeach; ?>
</table>
|
|
|
The layout and Logic part of the view
|
Logic part of the view
<?php
$title = ‘List of student’;
$content = include (‘template.php’);
?>
<html>
<head>
<title> <?php echo $title; ?></title>
</head>
<body>
<?php echo $content; ?>
<body>
</html>
|
|
|
 MVC pattern for php |
|
|
|
|
Related Articles:
http://www.tonymarston.net/php-mysql/model-view-controller.html
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
http://www.enode.com/x/markup/tutorial/mvc.html
http://msdn.microsoft.com/en-us/library/ms978748.aspx
|
|
|
Share this post
|
|
|
|
Posted in CMS, Design Pattern, PHP | Tagged: controller, design archetecture, model, model-view-controller, mvc, mvc and web application, mvc for php development, mvc pattern, PHP, php and mvc, view, web application design pattern, web design pattern | Leave a Comment »
Posted by Prabir Choudhury on October 22, 2009
|
Microsoft’s Windows 7 is finally here. The new perating system (OS) is the the company’s most important release after the disappointing performance of Vista, its earlier release. With Windows 7 Microsoft aims to once again strengthen its grip on the PC market.
Here’s looking into all that’s new in Windows 7. |
| |
| |
| |
|

|
| |
| Book mark this |
|
|
Posted in News, Technology, Uncategorized | Tagged: Home Premuam, new in windows 7, operating system, os, windows, windows 7, windows7 | 1 Comment »
Posted by Prabir Choudhury on October 15, 2009
|
DOM object.
DOM stands for the Document Object Model, and it’s a way of representing a document (could be it XML or HTML) using Object Oriented programming. It basically allows to have access to any part of the document we want by calling functions. DOM could be used in JavaScript, for parsing an XML document. DOM objects are real PHP object in PHP5. we could create new nodes by calling methods on a DOM object or could intantiate nodes as actual PHP objects
|
|
XSL
XSLT support, provided by the XSL extension in PHP 5, allows for the transformation of an XML document into another document. Rather than supporting two different extensions, as was the case with PHP 4, both Sablotron and domxml, providing some XSLT support, were moved to PECL. As a replacement, the XSL extension was created, providing the extensive functionality found in Sablotron, as well as the interoperability between DOM and XSL and the transformation speed from domxml. All of this made possible due to the use of the libxslt library.
XSLT
XSLT is a language for transforming XML documents into other XML documents. XSLT is itself written in XML, and belongs to the family of functional languages, which have a different approach to that of procedural and object-orientated languages like PHP.
There were two different XSLT processors implemented in PHP 4: Sablotron (in the more widely used and known xslt extension), and libxslt (within the domxml extension). The two APIs were not compatible with each other, and their feature sets were also different.
In PHP 5, only the libxslt processor is supported. Libxslt was chosen because it’s also based on libxml2 and therefore fits perfectly into the XML concept of PHP 5.
PHP 4
In php4, the xslt extension uses resources instead of object.
|
|
<?php
// load xml data
$xml = ‘xml_data.xml’;
$xml = ‘xml_data.xml’;
// load xml data
$xml = ‘xml_data.xml’;
// load xsl stylesheet
$xsl = ‘xsl_stylesheet’;
// Allocate a new XSLT processor
$xh = xslt_create();
// Process the document
$args = array ( ‘/_xml’ => $xmldata );
$params = array ( ’somevariable’ => ’somecontent’ );
$result .= xslt_process($xh, ‘arg:/_xml’, $xsl, NULL, $args,$params);
xslt_free($xh);
?>
|
|
|
PHP 5
Using XSLT in PHP5 involves two main steps.
1. preparing the XSLT objects.
2. triggering the actual transformation for each XML file.
to begin, load the stylesheet using DOM, then instantiate a new XSLTProcessor object and import the XSL documentby passing newly created DOM object.
|
|
<?php
/**call the XML data file from php function
*if the xml data generate dynamically then put those data into an xml file
*and save it in the server and then call this file from the server
*call the php function to generate dynamic data in an xml format.
**/
$xmldata=directory();
#write this xml data into a file in the server
$xmlfile = “directory /xml_data.xml”;
$file = fopen($xmlfile,”w”) or die(“can’t open file”);
fwrite($file, $xmldata);
fclose($file);
#load the xml file and stylesheet (xsl) as domdocuments
$xsl = new DomDocument();
$xsl->load(“directory/xsl_stylesheet.xsl”);
#load xml data
$xmlfiledata=”directory /xml_data.xml”;
$inputdom = new DomDocument();
$inputdom->load($xmlfiledata);
#create the processor and import the stylesheet
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);
#transform and output the xml document
$newdom = $proc->transformToDoc($inputdom);
$result = $newdom->saveXML();
print $result;
?>
|
|
| |
 Transforming XML with XSLT in PHP5 |
|
Related Articles:
http://php-mag.net/itr/online_artikel/psecom,id,503,nodeid,114.html
http://devzone.zend.com/article/2387
http://edn.embarcadero.com/article/27106
http://www.ctg.albany.edu/publications/reports/xml?chapter=9
|
Book mark this post
|
Posted in PHP, XML | Tagged: DOM Object, php4, php5, XML, xsl, xslt, xslt_create(), xslt_process() | Leave a Comment »
Posted by Prabir Choudhury on July 8, 2009

It’s been an exciting nine months since we launched the Google Chrome browser. Already, over 30 million people use it regularly. We designed Google Chrome for people who live on the web — searching for information, checking email, catching up on the news, shopping or just staying in touch with friends. However, the operating systems that browsers run on were designed in an era where there was no web. So today, we’re announcing a new project that’s a natural extension of Google Chrome — the Google Chrome Operating System. It’s our attempt to re-think what operating systems should be.
more >>>
Posted in News, Technology | Leave a Comment »
Posted by Prabir Choudhury on June 11, 2009
Another good site for the CMS user. This site is provided as a community service to everyone interested in looking for a means to manage web site content. Here you can discuss, rate, and compare the various systems available on the market today.
This site works because of community involvement! Please rate any systems you’ve used and discuss them in the forums. If you notice any errors, please report them via the feedback form located on each CMS’s listing page.
more >>>
Posted in CMS | Tagged: CMS, cms matris, cms statistics | Leave a Comment »
Posted by Prabir Choudhury on June 10, 2009
Zend Technologies, Inc., the PHP Company, announced today a new version 1.8 release of Zend Framework. The project is an open, collaborative web application framework for PHP development and deployment that includes contributions from the open source community and Zend partners.
Rapid application development (RAD) is now possible with Zend Framework 1.8’s automated and customizable creation of PHP-based web applications. This feature lets users create their own standards and processes for specific business needs when creating Zend Framework-based applications.
more >>>
Posted in News, PHP, Technology | Tagged: PHP, RAD, zend | Leave a Comment »
Posted by Prabir Choudhury on June 10, 2009

PHP MicroCMS (PHP MCMS) is a simple, but very powerful Content Management System that everyone can use. This script can be installed easily by web developers, webmasters, graphic designers, etc. PHP MCMS was developed in OOP and allows you to build websites in a few minutes and then easy add and edit the content.
PHP MicroCMS allows users with very little technical knowledge to build websites and it widely used by our customers due to its easy management tools. PHP MicroCMS requires NO knowledge of HTML, although HTML can be used to enhance the pages by adding headings, images, hyperlinks or simply to emphasize text.
The PHP MCMS is an excellent tool for those who:
- • Want to create web sites
- • Look for small, but powerful CMS
- • Need to build a secure web site quickly
more >>>
Posted in News, PHP | Tagged: CMS, microcms, PHP, php cms | Leave a Comment »
Posted by Prabir Choudhury on June 10, 2009
Sometimes it is necessary to know how large is the PHP market in the world or in a specific country.
It may help, for instance, developers to advocate for PHP, companies to decide for sponsoring PHP events, PHP training, developing of products targeting the PHP developers, or any other initiatives directed to the PHP market.
This article presents several sources of information that may help decision makers to invest more in the PHP market.
The article also covers the huge popularity of Firefox browser among PHP developers attributing it to the superb Web development extensions available for this browser. The most useful Firefox extensions for PHP developers are listed.
more >>>
Posted in News, PHP | Leave a Comment »