<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">

<channel>
	<title>Ciro Feitosa [.com]</title>
	<link>http://cirofeitosa.com/</link>
	<description>Development, Web Standards, Acessibility and related topics.</description>
	<language>pt-br</language>
	<copyright>Ciro Feitosa</copyright>
	<image>
		<title>Ciro Feitosa</title>
		<url>http://cirofeitosa.com/img/logo-rss.gif</url>
		<link>http://cirofeitosa.com/</link>
	</image>
	<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/ciro-english" type="application/rss+xml" /><item>
		<title>Smarty and PHP always together</title>
		<link>http://cirofeitosa.com/post/smarty-php-always-together</link>
		<comments>http://cirofeitosa.com/post/smarty-php-always-together#comentario</comments>
		<pubDate>Sat, 15 Jul 2006 16:52:37</pubDate>
		<dc:creator>Ciro Feitosa</dc:creator>
		<guid>http://cirofeitosa.com/post/smarty-php-always-together</guid>
		<description><![CDATA[In this article, I show the functioning and examples of the use of Smarty methods. You'll notice a profit of general productivity in the development of applications. ]]></description>
		<content:encoded><![CDATA[<p>When you discover the <a href="http://smarty.php.net/" rel="external">Smarty</a>, is almost impracticable to live without it. In this article, I show your functioning and examples of the use of methods. You will notice a profit of general productivity in the development of applications.</p>

<h2>What is Smarty?</h2>

<p>Definition of official site:</p>

<blockquote>Although Smarty is known as a "Template Engine", it would be more accurately described as a "Template/Presentation Framework." That is, it provides the programmer and template designer with a wealth of tools to automate tasks commonly dealt with at the presentation layer of an application. I stress the word Framework because Smarty is not a simple tag-replacing template engine. Although it can be used for such a simple purpose, its focus is on quick and painless development and deployment of your application, while maintaining high-performance, scalability, security and future growth.</blockquote>

<p>In other words, Smarty functions of a form that separates <strong>interface</strong> of the <strong>programming logic</strong> and has for objective, to facilitate and to improve the development of any application in PHP.</p>

<p>For very being spread out in the entire world, and to be on to the official site of the PHP, the Smarty it has a great community of developers. This aid in the support and quarrel of improvements.</p>

<p>Its last version (until the writing of this article) is the <a href="http://smarty.php.net/do_download.php?download_file=Smarty-2.6.14.tar.gz" rel="external">2.6.14</a> (<a href="http://smarty.php.net/changelog.php" rel="external">changelog</a>), launched in May of 2006.</p>

<h2>Great features</h2>

<p>Beyond the functionalities that I commented in previous article (<a href="/post/how-to-develop-better-in-the-web">How to develop better in the Web</a>), I list others:</p>

<ul>
	<li>A better execution performance.</li>
	<li>It finishes with overhead of template, therefore it compels only one time.</li>
	<li>Extensible: you can create its proper functions.</li>
	<li>You configure the syntax of tag of delimitation of template. Thus can be used {}, {{}}, &lt;!--{}--&gt;, etc.</li>
	<li>Use of conditional functions of form simplified inside of templates.</li>
	<li>Without limitation for loops, ifs, etc.</li>
	<li><a href="http://smarty.php.net/manual/en/caching.php" rel="external">Cache</a> mode inlaid.</li>
	<li><a href="http://smarty.php.net/manual/en/plugins.php" rel="external">Plugins</a> architecture.</li>
</ul>

<h2>Installation</h2>

<p>Download the <a href="http://smarty.php.net/do_download.php?download_file=Smarty-2.6.14.tar.gz" rel="external">package of Smarty</a>. Unzip all the folders. Verify a folder "demo", is the demonstration of functioning. Put the folder "libs" inside of the "demo". At final you'll get a folder organization, as shown below. Don't forget to give permission in folder "templates_c".</p>

<h2>Folder organization</h2>

<p>The default tree of directory of the Smarty is organized in the following way:</p>

<ul>
	<li><strong>/</strong> - In the root will be the logic archives (.PHP).</li>
	<li><strong>/configs</strong> - Configuration files. It is possible to setup a default title for all your system, and to use it in the template files.</li>
	<li><strong>/libs</strong> - Smarty libraries, where also she is located the main class.</li>
	<li><strong>/templates</strong> - Default directory localization of templates. They are archives of interface with the user.</li>
	<li><strong>/templates_c</strong> - Cache directory. It must be with writing permission.</li>
</ul>

<p>This architecture can be modified by the user, remembering that, after modified the names, you it will have to modify some lines of the <strong>Smarty.class.php</strong> (main class):</p>

<p><strong>Smarty.class.php:</strong></p>

<pre>
var $template_dir    =  'templates';
var $compile_dir     =  'templates_c';
var $config_dir      =  'configs';
</pre>

<h2>Let's go</h2>

<p>To program using Smarty is still more simple. All archive PHP must point to one <em>template</em>. The access the data base, critical more complex, and other logics are in archive PHP (as before). What dumb here, it is the simplicity of the syntax of templates, facilitating to changes in the future for the Designer or Developer: each one modifies its file.</p>

<p>As the topic suggests, I go direct to the subject. See a <strong>very simple example</strong> of the use of templates in the Smarty.</p>

<p><strong>index.php:</strong></p>

<pre>
&lt;?php
<em>/**
* Smarty folder setup in a Constant
*/</em>
define('PATH_SMARTY', '/path/to/smarty');

<em>/**
* Include the main class of Smarty
*/</em>
require PATH_SMARTY.'/Smarty.class.php';

<em>/**
* Instance Smarty and setup properties
*
* compile_check = tell the Smarty to show compile errors
* debugging = open a popup window with all information about the generate page
*/</em>
$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;

<em>/**
* Assign is the method of Smarty to create a new variable that will be used in the Template file
* syntax: assign->('variable_name', 'value');
*/</em>
$smarty->assign('name', 'Ciro');
$smarty->assign('lastname', 'Feitosa');

<em>/**
* Show the Template
*/</em>
$smarty->display('index.tpl');

?&gt;
</pre>

<p><strong>index.tpl:</strong></p>

<pre>
{config_load file=test.conf}

&lt;html&gt;
&lt;body&gt;
<strong>{$name} {$lastname}</strong>
&lt;/body&gt;
&lt;/html&gt;
</pre>

<p>When twirling <strong>index.php</strong> for the first time, automatically the Smarty will create one <em>cache</em> of the content generated in the <strong>/templates_c</strong> directory.</p>

<p>In this simple example, you perceive how simple is the syntax used for the Smarty, isn't it?! I'll present now, methods that will have to be used in the archives of <em>templates</em>.</p>

<h2>Private variable: $smarty</h2>

<p>The private variable <a href="http://smarty.php.net/manual/en/language.variables.smarty.php" rel="external">$smarty</a>, brings options to treat the information comings for methods GET, POST, or for Cookies, Sessions, etc. It sees examples of method calls:</p>

<pre>
{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
{$smarty.get.page}

{* display the variable "page" from a form ($_POST['page']) *}
{$smarty.post.page}

{* display the value of the cookie "username" ($_COOKIE['username']) *}
{$smarty.cookies.username}

{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
{$smarty.server.SERVER_NAME}

{* display the system environment variable "PATH" *}
{$smarty.env.PATH}

{* display the php session variable "id" ($_SESSION['id']) *}
{$smarty.session.id}

{* display the variable "username" from merged get/post/cookies/server/env *}
{$smarty.request.username}
</pre>

<p>Thus, in the call of forms you must insert in the field value: <strong>$smarty.post.field_name</strong>. Example:</p>

<p><strong>form.tpl:</strong></p>

<pre>
Name: &lt;input type="text" name="name" value="<strong>{$smarty.post.name}</strong>" /&gt;&lt;br /&gt;
State: &lt;select name="state"&gt;{html_options options=$states selected=<strong>$smarty.post.state</strong>}&lt;/select&gt;
</pre>

<h2>Methods that help</h2>

<p>The <a href="http://smarty.php.net/manual/en/" rel="external">documentation</a> of the Smarty is excellent. Therefore, I will not try to explain what already it exists, but to quickly show useful functions in day-by-day.</p>

<p>To help in the agreement, I will use forms. I believe that this is the use where more aid, when you uses Smarty. It estimates that you already it has enclosed the class of the Smarty and instance the class (it reviews the example in the sub-topic "Let's go"). They do not observe code validations <acronym title="eXtensible Hypertext Markup Language">xHTML</acronym>, therefore it is not the central idea here.</p>

<h2>Variable Modifiers</h2>

<p>They are used, mainly, to modify strings. Functions of the type to <a href="http://smarty.php.net/manual/en/language.modifiers.php#language.modifier.capitalize" rel="external">capitalize</a>, to <a href="http://smarty.php.net/manual/en/language.modifier.count.characters.php" rel="external">count characters</a>, to <a href="http://smarty.php.net/manual/en/language.modifier.count.paragraphs.php" rel="external">count paragraphs</a>, to <a href="http://smarty.php.net/manual/en/language.modifier.upper.php" rel="external">change to uppercase letters</a>, to <a href="http://smarty.php.net/manual/en/language.modifier.indent.php" rel="external">indent lines</a>, etc.</p>

<p>Sees an example of the <a href="http://smarty.php.net/manual/en/language.modifier.cat.php" rel="external">cat</a> method, that it functions concatenating 2 strings (<a href="http://smarty.php.net/manual/en/language.modifiers.php" rel="external">sees all the variable modifiers methods</a>).</p>

<p><strong>index.tpl:</strong></p>
<pre>
&lt;html&gt;
&lt;body&gt;
<strong>{$nome|cat:" is the owner of this Blog."}</strong>

&lt;/body&gt;
&lt;/html&gt;
</pre>

<h2>Internal functions</h2>

<p>Are functions used internally for templates. Loops, conditional (if, else), includes. See the list complete of <a href="http://smarty.php.net/manual/en/language.builtin.functions.php" rel="external">internal functions</a>.</p>

<p>The <strong>conditional</strong> functions, as well as in any language, are used when is had a condition. Imagine that you possess a done system with login with session. If the user will have logado, shows the name of it, in case that contrary, shows "Guest". He sees as to make this using templates of the Smarty:</p>

<pre>
<strong>{if $smarty.session.name != ''}</strong>
{$smarty.session.name}
<strong>{else}</strong>
Guest
<strong>{/if}</strong>
</pre>

<h2>Custom functions</h2>

<p>Servants similar of if creating of automatized form had been, some works repetitive. In if treating to forms, she is possible to generate <a href="http://smarty.php.net/manual/en/language.function.html.checkboxes.php" rel="external">checkboxes</a>, <a href="http://smarty.php.net/manual/en/language.function.html.options.php" rel="external">menus drop-downs</a>, <a href="http://smarty.php.net/manual/en/language.function.html.radios.php" rel="external">radios</a>, and drop-downs menus of <a href="http://smarty.php.net/manual/en/language.function.html.select.date.php" rel="external">date</a> and <a href="http://smarty.php.net/manual/en/language.function.html.select.time.php" rel="external">hour</a>, everything this being able to come of a static or dynamic Array (filled way database, for example). 

<p>Imagine that you it has an Array with the country states (in an file .PHP) and desires to generate a menu drop-down in the screen. Uses the <a href="http://smarty.php.net/manual/en/language.function.html.options.php" rel="external">html_options</a> method. Beyond this, it exists sets of ten of <a href="http://smarty.php.net/manual/en/language.custom.functions.php" rel="external">custom functions</a>.</p>

<p><strong>form.php:</strong></p>
<pre>
$arrayStates = array(
	1 => 'Alabama',
	2 => 'Alaska',
	3 => 'Arizona',
	4 => 'Arkansas',
	5 => 'California',
	6 => 'Colorado',
	7 => 'Connecticut',
	8 => 'Delaware',
	9 => 'District of Columbia',
	10 => 'Florida',
	11 => 'Georgia',
	12 => 'Hawaii',
	13 => 'Idaho',
	14 => 'Illinois',
	15 => 'Indiana',
	16 => 'Iowa',
	17 => 'Kansas',
	18 => 'Kentucky',
	19 => 'Louisiana',
	20 => 'Maine',
	21 => 'Maryland',
	22 => 'Massachusetts',
	23 => 'Michigan',
	24 => 'Minnesota',
	25 => 'Mississippi',
	26 => 'Missouri',
	27 => 'Montana',
	28 => 'Nebraska',
	29 => 'Nevada',
	30 => 'New Hampshire',
	31 => 'New Jersey',
	32 => 'New Mexico',
	33 => 'New York',
	34 => 'North Carolina',
	35 => 'North Dakota',
	36 => 'Ohio',
	37 => 'Oklahoma',
	38 => 'Oregon',
	39 => 'Pennsylvania',
	40 => 'Rhode Island',
	41 => 'South Carolina',
	42 => 'South Dakota',
	43 => 'Tennessee',
	44 => 'Texas',
	45 => 'Utah',
	46 => 'Vermont',
	47 => 'Virginia',
	48 => 'Washington',
	49 => 'West Virginia',
	50 => 'Wisconsin',
	51 => 'Wyoming'
	);
$smarty->assign('states',$arrayStates);

$smarty->display('form.tpl');
</pre>

<p><strong>form.tpl:</strong></p>
<pre>

&lt;html&gt;
&lt;body&gt;
&lt;select name="state"&gt;<strong>{html_options options=$states}</strong>&lt;/select&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>


<h2>Conclusion</h2>

<p>Is notable the increase of the productivity using this system of templates. When we work in a team, Designer and Developer with distinct functions, and in this in case that, working in addition together. If the Designer to want to modify one label of a field of the form, for example, will only need to move in template.</p>

<p>For more information, please visit the <a href="http://smarty.php.net/" rel="external">Smarty official site</a>.]]></content:encoded>
	</item>
	<item>
		<title>How to develop better in the Web</title>
		<link>http://cirofeitosa.com/post/how-to-develop-better-in-the-web</link>
		<comments>http://cirofeitosa.com/post/how-to-develop-better-in-the-web#comentario</comments>
		<pubDate>Thu, 13 Jul 2006 19:22:46</pubDate>
		<dc:creator>Ciro Feitosa</dc:creator>
		<guid>http://cirofeitosa.com/post/how-to-develop-better-in-the-web</guid>
		<description><![CDATA[This article show a general idea about the process of development in the Web. Techniques and methods to improve your productivity and to reach a good quality in a project. ]]></description>
		<content:encoded><![CDATA[<p>Hi! This is the first article wrote in <strong>english version</strong> of Ciro Feitosa's personal site. It is a translation of the most read article <em><a href="http://cirofeitosa.com.br/post/como-desenvolver-melhor-na-web">Como desenvolver melhor na Web</a></em> (written in Portuguese).</p>

<p>It makes time sufficiently that I follow some professionals in this area, and I see to sin in some points. In the University, already it heard to speak of <a href="http://en.wikipedia.org/wiki/Software_engineering" rel="external">Software Engineering</a>, and in elapsing of my projects I was placing in practical. I all observed a significant improvement in the development process, since the requirements of systems until the final tests, passing for the general documentation.</p>

<p>I won't show the importance of other professionals who can be part of a project, as it is the case of an Analyst of Systems. But it is good that you it knows that, most of the time, will go to work with people of diverse areas and well varied formation.</p>

<p>This article does not contain codes, it is not the general idea. But I intend to create others focando more what all programmer likes: <strong>codes</strong>.</p>

<h2>Which language to choose?</h2>

<p><a href="http://www.php.net/" rel="external">PHP</a>, <a href="http://www.asp.net/" rel="external">ASP</a>, <a href="http://java.sun.com/products/jsp/" rel="external">JSP</a>, <a href="http://www.macromedia.com/go/gnavtray_cfmx_home" rel="external">ColdFusion</a>, <a href="http://www.perl.com/" rel="external">Perl</a>, <a href="http://www.python.org/" rel="external">Python</a>? Many people still argue or until they defend with nails and teeth the choice of one language. To such choice it goes to depend on some factors. Where the system goes to twirl (infrastructure, architecture, operational system, etc.)? Which the vital necessities? In determined task, which offers to the relation performance and more competitive security?</p>

<p>Already see great products developed under the use of different languages. This can very be good in some aspects, but in if treating to code maintenance, it can generate a problem of the great ones.</p>

<p>Of more than the 10 projects that already I participated, always I made use of the PHP. The PHP is today, the most used server-side language around of the world. It offers speed of very good execution, has supported the diverse types of <acronym title="Database Management Systems">DBMS's</acronym>, flexibility of syntax, easiness of learning for using futures that come to work in the project, amongst others.</p>

<p>But my paper is not here to praise the PHP, I am only demonstrating that with a language if it can make much thing (already I made) and more below I will present a classroom that helps very in the development.</p>

<h2>Does not exaggerate in the treatments</h2>

<p>The use of the Javascript also will be part of a Web project. Who is it controls the side of the customer, very used for example in form treatments. But it attempts against for the writing of a valid code in all the navigators. The Brazilian site <a href="http://www.jsfromhell.com/" rel="external">JSFromHell</a> (also in english version) brings diverse well written and efficient examples of scripts in what they make, valley the visit.</p>

<p>Very well-taken care of not to create excesses of treatment in the side of the customer for some reasons:</p>

<ul>
	<li>It overloads the processing of the side of the customer.</li>
	<li>It reduces the compatibility for some devices.</li>
	<li>The customer can disactivate the use of Javascript in browser.</li>
</ul>

<p>Observing one of these affirmations, you it observes that the total treatment always must be in the side of the server.</p>

<h2>Tools that help</h2>

<p>Nor of codes a desenvolvedor only lives.</p>

<p><img src="/img/artigo-desenvolve-melhor-dbdesigner.jpg" alt="Screenshots of DBDesigner" class="img-dir" />To the times, in projects of small average e transport, the proper professional will be puted in charge to project the data base. It has time sufficiently that I come using the <a href="http://www.fabforce.net/dbdesigner4" rel="external">DBDesigner</a> of <a href="http://www.fabforce.net/" rel="external">fabForce</a>. Software leaves to desire in some points, but it supplies many necessities. It possesss integration to the <acronym title="Database Management System">DBMS</acronym> <a href="http://www.mysql.com/" rel="external">MySQL</a>, exporting and importing tables and relationships. For example, you can diagramar all the tables and relations direct in the DBDesigner and, in only 1 click, export everything this it MySQL and to start to work. If to prefer, it still exports in SQL to importation in other <acronym title="Database Management Systems">DBMS's</acronym>.</p>

<p>In Windows environment, the <a href="http://www.mysqlfront.de/" rel="external">MySQL-Front</a> helps in the management of the information and tests of integrity. By Web, the celebrity <a href="http://www.phpmyadmin.net/" rel="external">phpMyAdmin</a> breaks a twig in the remote administration.</p>

<h2>Improving the productivity</h2>

<p>If you not yet it heard to speak in <a href="http://smarty.php.net/" rel="external">Smarty</a>, I advise to give a chore in this incredible classroom of templates. The Smarty offers diverse resources to you, that after making use, go to be well difficult not to develop (pra not to say "to live") without it (as broad band and TV for signature). Some of them (see the section <a href="http://smarty.php.net/rightforme.php" rel="external">Why Use Smarty</a>):</p>

<ul>
	<li><strong>Programming and Layout:</strong> as a system of templates, the programming and the final layout are separate. This improvement the relation of the programmer and architect of interface, the two works together, improving the final productivity.</li>
	<li><strong>Cache:</strong> to provide cache with templates generated, increasing the execution speed.</li>
	<li><strong>Security:</strong> the archives of templates do not contain codes PHP, therefore designer of the application will not have access of the side of the server.  Easy to use and to move: templates possesss simple syntax, that will facilitate the use for the architect of interface and later the alteration.</li>
	<li><strong>Ready functions:</strong> diverse functions can be used in templates, as for example generation of menus drop-downs to apartir of data of data base for example.</li>
</ul>

<p>In this article I do not go to enter in details of code of the Smarty, will be for another one post.</p>

<h2>Web Standards in the development</h2>

<p>The Web Standards could not be out of this. Speaking still of productivity, the separation of the code <acronym title="eXtensible Hypertext Markup Language">xHTML</acronym> of presentation <acronym title="Cascading Style Sheets">CSS</acronym>, improves the relation enters the architect of interface and to designer. Going more beyond, a good writing <acronym title="eXtensible Hypertext Markup Language">xHTML</acronym> will also increase the accessibility of the end item.</p>

<p>It imagines that a manager requests a product, passes for all the phases of the development, he is ready, and one month later is needed to develop a version for <acronym title="Personal Digital Assistant">PDA</acronym> for example. What to make? If it will have it are of the standards, with certainty it will have that if to create a new and directed version for the device. This demand more time and clearly, more cost.</p>

<p>It is in this point that the Web Standards helps: it reduces cost and it improves accessibility. Why still it has people that she insists on not using?</p>

<h2>It registers</h2>

<p>One of the objectives for the creation of the documentation is to facilitate posterior maintenances for you or people who come to work in the project. To create a <a href="http://en.wikipedia.org/wiki/Entity-relationship_model" rel="external">Entity-Relationship Diagram</a> (<acronym title="Entity-Relationship Diagram">ERD</acronym>) for example, already is an example of documentation of the database.</p>]]></content:encoded>
	</item>
</channel>
</rss>
