Php using smarty by Nishant
Till now i developed most of my projects using asp.net. Just last month only i learned PHP (PHP: Hypertext Preprocessor) is a programming language designed for producing dynamic Web pages. PHP is an open source language and considered to be free software by the Free Software Foundation. At this time, i discovered Smarty and have been using it in my projects.
Now the question is why do we use Smarty and what is the purpose of using it...???
Traditionally, when you make a web application using php, html and php scripts are mixed in one file. More often than not, a programmer finishes a complete project, and someone suggests that the font and background colors chosenhe/his choose don't match with their requirement. The programmer would then hasve to search through dozens of php files and alter the HTML that was embedded within simply to change the appearance of the web site and change all other properties. Editing the php files greatly increases the chance of generatinge new errors or bugs. It will much easier when you separate your HTML from your PHP code and will also make it much easier to reuse your PHP code down the road in other projects.
So the above solution can be applied by using Smarty technology as, it allows you to change the appearance of your web site by changing an HTML template file. It also allows you to do simple if statements, dynamic repeating blocks, and variable substitution.
The basic use of Smarty is for separation of business logic and presentation logic, generates web content by the placement of special Smarty tags within a document. So it allows the presentation of a web page to change separately from the back-end, thus allowing applications to be developed in a more organized fashion. Using this development model, designers are hidden from the back-end coding and PHP programmers are hidden from the presentation coding.
Tasks of both designer and programmer are is as follows :
Programmer's Tasks:
-> Fetching data from database by firing simple queries to it. -> Manipulate or validate the data by performing business logic on it. -> The best thing is that we can change the data access method like from MySql to another without interfering with designer's work.
Designer's Task:
->Creating HTML pages without affecting php scripts , only concerned is with placing content elements on the right place where the programmer has agreed to provide.
Some of the attractive features of using smarty areis as follows :
1) Fast : Smarty is extremely fast by doing Template Compiling, means it reads the templates, creates php scripts and include the php files which is finally compiled by php engine..The best thing is that the templates are parsed only once by smarty if it is not modified again.. this results in to fast compilation and better performance.
2) Catching : Smarty has built-in catching of your template outputs. It catches the output of the template contents and thus saves the overhead of retrieving the data from data source.
3) Variable Modifiers : Smarty provides variable modifiers in order to modify the contents of a variable like converting string to uppercase or lowercase or truncating etc things like that very easily
4) Template Function : Smarty provides some builtin and custom functions like looping function like if statements or for loops etc.Or just write a simple one line code which will generate a radiobuttons or calendar or other form controls which make things faster and more simple.r.
Smarty is a great tool for both designers and developers. By using Smarty you can reduce the site development and maintenance times. If you are a developer you no longer need to mix PHP code with HTML code. Just take care of business logic and leave the HTML to the designer
Now the matter of debugging the smarty php scripts. Nusphere provides PHP Editor for editing and debugging..Ii'ss latest verison is PhpEd version 4.6.2 has been released with full support for PHP 5.2.
The definitive resource for learning Smarty is smarty.php.net,where you will get all the stuffs related to Smarty.
Till now i developed most of my projects using asp.net. Just last month only i learned PHP (PHP: Hypertext Preprocessor) is a programming language designed for producing dynamic Web pages. PHP is an open source language and considered to be free software by the Free Software Foundation. At this time, i discovered Smarty and have been using it in my projects.
Now the question is why do we use Smarty and what is the purpose of using it...???
Traditionally, when you make a web application using php, html and php scripts are mixed in one file. More often than not, a programmer finishes a complete project, and someone suggests that the font and background colors chosenhe/his choose don't match with their requirement. The programmer would then hasve to search through dozens of php files and alter the HTML that was embedded within simply to change the appearance of the web site and change all other properties. Editing the php files greatly increases the chance of generatinge new errors or bugs. It will much easier when you separate your HTML from your PHP code and will also make it much easier to reuse your PHP code down the road in other projects.
So the above solution can be applied by using Smarty technology as, it allows you to change the appearance of your web site by changing an HTML template file. It also allows you to do simple if statements, dynamic repeating blocks, and variable substitution.
The basic use of Smarty is for separation of business logic and presentation logic, generates web content by the placement of special Smarty tags within a document. So it allows the presentation of a web page to change separately from the back-end, thus allowing applications to be developed in a more organized fashion. Using this development model, designers are hidden from the back-end coding and PHP programmers are hidden from the presentation coding.
Tasks of both designer and programmer are is as follows :
Programmer's Tasks:
-> Fetching data from database by firing simple queries to it. -> Manipulate or validate the data by performing business logic on it. -> The best thing is that we can change the data access method like from MySql to another without interfering with designer's work.
Designer's Task:
->Creating HTML pages without affecting php scripts , only concerned is with placing content elements on the right place where the programmer has agreed to provide.
Some of the attractive features of using smarty areis as follows :
1) Fast : Smarty is extremely fast by doing Template Compiling, means it reads the templates, creates php scripts and include the php files which is finally compiled by php engine..The best thing is that the templates are parsed only once by smarty if it is not modified again.. this results in to fast compilation and better performance.
2) Catching : Smarty has built-in catching of your template outputs. It catches the output of the template contents and thus saves the overhead of retrieving the data from data source.
3) Variable Modifiers : Smarty provides variable modifiers in order to modify the contents of a variable like converting string to uppercase or lowercase or truncating etc things like that very easily
4) Template Function : Smarty provides some builtin and custom functions like looping function like if statements or for loops etc.Or just write a simple one line code which will generate a radiobuttons or calendar or other form controls which make things faster and more simple.r.
Smarty is a great tool for both designers and developers. By using Smarty you can reduce the site development and maintenance times. If you are a developer you no longer need to mix PHP code with HTML code. Just take care of business logic and leave the HTML to the designer
Now the matter of debugging the smarty php scripts. Nusphere provides PHP Editor for editing and debugging..Ii'ss latest verison is PhpEd version 4.6.2 has been released with full support for PHP 5.2.
The definitive resource for learning Smarty is smarty.php.net,where you will get all the stuffs related to Smarty.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home