<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>rafaeldx7</title>
 <link href="http://tom.preston-werner.com/atom.xml" rel="self"/>
 <link href="http://rafaeldx7.github.com/"/>
 <updated>2011-06-23T18:32:29-03:00</updated>
 <id>http://rafaeldx7.github.com/</id>
 <author>
   <name>Rafael Carvalho</name>
   <email>rafaeldx7@gmail.com</email>
 </author>

 
 <entry>
   <title>Autorização com CanCan</title>
   <link href="http://rafaeldx7.github.com/2010/10/25/autorizacao-com-cancan.html"/>
   <updated>2010-10-25T00:00:00-02:00</updated>
   <id>http://rafaeldx7.github.com/2010/10/25/autorizacao-com-cancan</id>
   <content type="html">&lt;h1&gt;Autorização com CanCan&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;25 . 10 . 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Na última sexta-feira, eu fiz uma apresentação sobre o &lt;a href=&quot;http://github.com/ryanb/cancan&quot;&gt;CanCan&lt;/a&gt; para o pessoal do &lt;a href=&quot;http://tecnologia.proac.uff.br&quot;&gt;&lt;span class=&quot;caps&quot;&gt;NTP&lt;/span&gt;&lt;/a&gt;. Foi bem no estilo de uma TechTalk e as pessoas puderam participar bastante. O objetivo foi mostrar uma visão geral do &lt;a href=&quot;http://github.com/ryanb/cancan&quot;&gt;CanCan&lt;/a&gt; fazendo uma pequena comparação com o &lt;a href=&quot;http://github.com/be9/acl9&quot;&gt;Acl9&lt;/a&gt;, o qual o pessoal já conhecia.&lt;/p&gt;
&lt;p&gt;Para quem não conhece, o &lt;a href=&quot;http://github.com/ryanb/cancan&quot;&gt;CanCan&lt;/a&gt; e &lt;a href=&quot;http://github.com/be9/acl9&quot;&gt;Acl9&lt;/a&gt; são ferramentas de autorização para &lt;a href=&quot;http://rubyonrails.org&quot;&gt;Rails&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Abaixo, os slides da apresentação.&lt;/p&gt;
&lt;div style=&quot;width:425px&quot; id=&quot;__ss_5557797&quot;&gt;&lt;strong style=&quot;display:block;margin:12px 0 4px&quot;&gt;&lt;a href=&quot;http://www.slideshare.net/rafaeldx7/cancan&quot; title=&quot;Autorização com CanCan&quot;&gt;Autorização com CanCan&lt;/a&gt;&lt;/strong&gt;&lt;object id=&quot;__sse5557797&quot; width=&quot;425&quot; height=&quot;355&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=cancan-101025134241-phpapp01&amp;stripped_title=cancan&amp;userName=rafaeldx7&quot; /&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;/&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot;/&gt;&lt;embed name=&quot;__sse5557797&quot; src=&quot;http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=cancan-101025134241-phpapp01&amp;stripped_title=cancan&amp;userName=rafaeldx7&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;425&quot; height=&quot;355&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div style=&quot;padding:5px 0 12px&quot;&gt;View more &lt;a href=&quot;http://www.slideshare.net/&quot;&gt;presentations&lt;/a&gt; from &lt;a href=&quot;http://www.slideshare.net/rafaeldx7&quot;&gt;rafaeldx7&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Ruby: Usando o método grep</title>
   <link href="http://rafaeldx7.github.com/2010/10/22/ruby--usando-o-m--todo-grep.html"/>
   <updated>2010-10-22T00:00:00-02:00</updated>
   <id>http://rafaeldx7.github.com/2010/10/22/ruby--usando-o-m--todo-grep</id>
   <content type="html">&lt;h1&gt;Ruby: Usando o método grep&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;22 . 10 . 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;O módulo &lt;a href=&quot;http://ruby-doc.org/ruby-1.9/classes/Enumerable.html&quot;&gt;Enumerable&lt;/a&gt; do Ruby tem vários métodos que facilitam bastante a vida quando estamos trabalhando com coleções. Um deles é o método &lt;a href=&quot;http://ruby-doc.org/ruby-1.9/classes/Enumerable.html#M003121&quot;&gt;&lt;code&gt;grep&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Por exemplo, ao buscar os métodos públicos da classe &lt;a href=&quot;http://ruby-doc.org/ruby-1.9/classes/Object.html&quot;&gt;&lt;code&gt;Object&lt;/code&gt;&lt;/a&gt;, obtemos:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;ruby-1.9.2-p0 &amp;gt; Object.public_methods&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; [:allocate, :new, :superclass, :freeze, :===, :==, :&amp;lt;=&amp;gt;, :&amp;lt;, :&amp;lt;=, :&amp;gt;, :&amp;gt;=, :to_s, :included_modules, :include?, :name, :ancestors, :instance_methods, :public_instance_methods, :protected_instance_methods, :private_instance_methods, :constants, :const_get, :const_set, :const_defined?, :const_missing, :class_variables, :remove_class_variable, :class_variable_get, :class_variable_set, :class_variable_defined?, :module_exec, :class_exec, :module_eval, :class_eval, :method_defined?, :public_method_defined?, :private_method_defined?, :protected_method_defined?, :public_class_method, :private_class_method, :autoload, :autoload?, :instance_method, :public_instance_method, :nil?, :=~, :!~, :eql?, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :__id__, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Uma coleção grande, com noventa e cinco elementos do tipo &lt;a href=&quot;http://ruby-doc.org/ruby-1.9/classes/Symbol.html&quot;&gt;&lt;code&gt;Symbol&lt;/code&gt;&lt;/a&gt;. Se precisarmos pegar todos os &lt;code&gt;symbols&lt;/code&gt; que contêm &amp;#8220;instance&amp;#8221; no nome, podemos fazer assim:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;ruby-1.9.2-p0 &amp;gt; Object.public_methods.grep /instance/&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;=&amp;gt; [:instance_methods, :public_instance_methods, :protected_instance_methods, :private_instance_methods, :instance_method, :public_instance_method, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :instance_eval, :instance_exec]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Repare que &lt;code&gt;/instance/&lt;/code&gt; é uma expressão regular passada como parâmetro para o &lt;code&gt;grep&lt;/code&gt;. Podemos também procurar por um nome específico.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;ruby-1.9.2-p0 &amp;gt; Object.public_methods.grep :send&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; [:send]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Retornou um array com o symbol que procuramos. Caso não fosse encontrado, receberíamos um array vazio. Usar o método &lt;code&gt;grep&lt;/code&gt; dessa forma não faz muito sentido. Nesse caso o método &lt;code&gt;include?&lt;/code&gt; pode ser mais útil.&lt;/p&gt;
&lt;p&gt;Mas e se temos uma coleção com objetos de diversos tipos diferentes e queremos pegar apenas aqueles de um tipo específico? Vamos supor a seguinte coleção com elementos dos tipos &lt;a href=&quot;http://ruby-doc.org/ruby-1.9/classes/Fixnum.html&quot;&gt;&lt;code&gt;Fixnum&lt;/code&gt;&lt;/a&gt; e &lt;code&gt;Array&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;ruby-1.9.2-p0 &amp;gt; foo = [1, 2, 3, [2, 3], [7, 2], {:a=&amp;gt;:b}]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; [1, 2, 3, [2, 3], [7, 2], {:a=&amp;gt;:b}]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Pra pegar apenas os objetos do tipo &lt;code&gt;Fixnum&lt;/code&gt;, poderíamos fazer algo do tipo:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;ruby-1.9.2-p0 &amp;gt; foo.select { |element| element.is_a? Fixnum }&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; [1, 2, 3]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Funciona bem. Mas assim parece mais interessante:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;ruby-1.9.2-p0 &amp;gt; foo.grep Fixnum&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; [1, 2, 3]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Analogamente, se quisermos pegar os elementos que são &lt;code&gt;Array&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;ruby-1.9.2-p0 &amp;gt; foo.grep Array&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; [[2, 3], [7, 2]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;E o mais interessante: podemos pegar aqueles que têm módulos em comum:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;ruby-1.9.2-p0 &amp;gt; foo.grep Enumerable&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; [[2, 3], [7, 2], {:a=&amp;gt;:b}]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Excelente!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>A importância do attr_accessible no Rails</title>
   <link href="http://rafaeldx7.github.com/2010/09/15/a-import--ncia-do-attr_accessible-no-rails.html"/>
   <updated>2010-09-15T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/09/15/a-import--ncia-do-attr_accessible-no-rails</id>
   <content type="html">&lt;h1&gt;A importância do attr_accessible no Rails&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;15 . 09 . 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Rails: 2.3.x&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Não vejo esse assunto sendo muito abordado e acho que é muito importante que todo desenvolvedor Rails conheça. Isso é essencial para a segurança da aplicação.&lt;/p&gt;
&lt;h2&gt;attr_accessible != attr_accessor&lt;/h2&gt;
&lt;p&gt;A primeira coisa que temos que saber é que esses dois métodos são completamente diferentes.&lt;/p&gt;
&lt;p&gt;O &lt;code&gt;attr_accessor&lt;/code&gt; já vem com a linguagem Ruby. Ele é usado para criar variáveis de instância e seus devidos métodos de acesso.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Mod&lt;/span&gt;
  &lt;span class=&quot;kp&quot;&gt;attr_accessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:one&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:two&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;Fonte: &lt;a href=&quot;http://ruby-doc.org/docs/ProgrammingRuby/html/ref_c_module.html#Module.attr_accessor&quot;&gt;Programming Ruby&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;O que é attr_accessible?&lt;/h2&gt;
&lt;p&gt;O &lt;code&gt;attr_accessible&lt;/code&gt; é um método criado pelo Rails. Ele é usado para especificarmos quais atributos de um modelo podem ser alterados via atribuição em massa, como &lt;code&gt;update_attributtes(attrs)&lt;/code&gt; e &lt;code&gt;new(attrs)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Por padrão, os métodos de atribuição em massa aceitam um hash com os valores que desejamos passar para o objeto. Por exemplo:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;no&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Darth Vader&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:email&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;vader@sith.com&amp;#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Esse código vai criar um objeto User com os atributos name e email com os valores passados no hash. Podemos usar a atribuição em massa também na atualização de um objeto:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;sith&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find_by_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Darth Sidious&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;update_attributtes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:email&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;sidious@sith.com&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;live&amp;#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Alguém pode se aproveitar disso e alterar dados que simplesmente quebram as regras de negócio da sua aplicação e acabam com a brincadeira.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;sith&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find_by_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Darth Sidious&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;update_attributtes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:power&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;dead&amp;#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;.&lt;/p&gt;
&lt;h2&gt;Na prática&lt;/h2&gt;
&lt;p&gt;Os exemplos acima servem apenas para explicar o que fazem os métodos de atribuição em massa. Mas na prática, esses métodos são usados em nossos controllers dessa forma:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;update&lt;/span&gt;
  &lt;span class=&quot;vi&quot;&gt;@user&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Users&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;vi&quot;&gt;@user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;update_attributes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# atribuição de dados em massa.&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;redirect_to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;vi&quot;&gt;@user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:notice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;User updated.&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:action&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;edit&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Esse é o código de uma action update do Rails. Em geral ele não foge muito desse padrão. E quando não queremos que o usuário consiga alterar algum atributo, retiramos esse atributo do formulário na view. Mas isso não é suficiente. Alguém poderia tentar forçar o envio de dados que não estão no formulário. Daí quando chegarmos em &lt;code&gt;@user.update_attributes(params[:user])&lt;/code&gt;, tudo que chegou em &lt;code&gt;params[:user]&lt;/code&gt; será salvo. Assim conseguiriam alterar todos os atributos de um objeto, bastando conhecer o nome de cada um.&lt;/p&gt;
&lt;h3&gt;Como evitar a tragédia&lt;/h3&gt;
&lt;p&gt;&amp;#8220;O &lt;span class=&quot;caps&quot;&gt;RAILS&lt;/span&gt; É &lt;span class=&quot;caps&quot;&gt;INSEGURO&lt;/span&gt;&amp;#8221; &amp;#8211; dirá a oposição. Mas não contavam com a nossa astúcia!&lt;/p&gt;
&lt;p&gt;Existem algumas maneiras óbvias (e outras suicidas) de evitarmos isso. Podemos pensar em retirar do &lt;code&gt;params[:user]&lt;/code&gt; todos os atributos que não queremos permitir a atualização. Assim:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:id_god&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:power&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Isso funciona, mas vai deixar o seu controller enorme, dependendo da quantidade de atributos que temos. Podemos criar algum método pra fazer algo parecido também. Mas teríamos que chamar esse método em todas as actions &lt;code&gt;create&lt;/code&gt; e &lt;code&gt;update&lt;/code&gt; da nossa aplicação. E isso iria adicionando mais complexidade a nossa aplicação.&lt;/p&gt;
&lt;p&gt;Queremos apenas que os dados de um formulários, quando ele for submetido, sejam salvos de forma segura. Esse é o objetivo do negócio. Tem que existir uma forma de fazer isso sem adicionar muita complexidade a essa tarefa tão simples. Existe uma maneira de separar os meninos dos homens!&lt;/p&gt;
&lt;h2&gt;Usando o attr_accessible&lt;/h2&gt;
&lt;p&gt;Podemos adicionar o código abaixo no modelo User:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;attr_accessible&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:email&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Pronto. Somente os atributos &lt;code&gt;name&lt;/code&gt; e &lt;code&gt;email&lt;/code&gt; poderão ser atualizados por atribuição em massa. Todos os outros serão ignorados. Simples?&lt;/p&gt;
&lt;h2&gt;O que isso não faz?&lt;/h2&gt;
&lt;p&gt;O método &lt;code&gt;attr_accessible&lt;/code&gt; não é controle de acesso. Ele apenas não permite atualizar em massa o que não queremos que seja atualizado em massa.&lt;/p&gt;
&lt;p&gt;Os atributos não ficam imutáveis. Ele apenas não permite atualizar em massa o que não queremos que seja atualizado em massa (2). O seguinte código continua funcionando:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;sith&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;power&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;999999&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Mas esse tipo de atribuição não usada para atualizar um objeto com dados que vêm de fora da aplicação. Em geral, o que se faz é &lt;code&gt;user = User.new(params[:user])&lt;/code&gt; na action create e &lt;code&gt;@user.update_attributes(params[:user])&lt;/code&gt; na action update. Então, usando o &lt;code&gt;attr_accessible&lt;/code&gt; sua aplicação estará segura contra os problemas que falamos no ínicio.&lt;/p&gt;
&lt;p&gt;Também existe o &lt;code&gt;attr_protected&lt;/code&gt;, que funciona de maneira análoga, mas recebe os nomes dos atributos que queremos proteger, deixando liberados todos os outros.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>RubyConf - Agora eu vou!</title>
   <link href="http://rafaeldx7.github.com/2010/09/10/rubyconf---agora-eu-vou-.html"/>
   <updated>2010-09-10T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/09/10/rubyconf---agora-eu-vou-</id>
   <content type="html">&lt;h1&gt;RubyConf &amp;#8211; Agora eu vou!&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;10 . 09 . 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Fiquei muito feliz com o sorteio do ingresso da &lt;a href=&quot;http://www.rubyconf.com.br&quot;&gt;RubyConf&lt;/a&gt; pelo &lt;a href=&quot;http://www.rubyinside.com.br&quot;&gt;RubyInside&lt;/a&gt; com apenas um RT! Sensacional!!! =D&lt;/p&gt;
&lt;div style=&quot;text-align: center&quot;&gt;
&lt;a href=&quot;http://www.flickr.com/photos/12559210@N08/4977563659/&quot; title=&quot;Screen shot 2010-09-10 at 7.49.27 PM by rafaeldx7, on Flickr&quot;&gt;&lt;img src=&quot;http://farm5.static.flickr.com/4087/4977563659_3d68f573ae.jpg&quot; width=&quot;500&quot; height=&quot;226&quot; alt=&quot;Screen shot 2010-09-10 at 7.49.27 PM&quot; /&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.flickr.com/photos/12559210@N08/4978172812/&quot; title=&quot;Screen shot 2010-09-10 at 7.48.13 PM by rafaeldx7, on Flickr&quot;&gt;&lt;img src=&quot;http://farm5.static.flickr.com/4105/4978172812_c0a84be602.jpg&quot; width=&quot;500&quot; height=&quot;379&quot; alt=&quot;Screen shot 2010-09-10 at 7.48.13 PM&quot; /&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;p&gt;Obrigado!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Importação Feita!</title>
   <link href="http://rafaeldx7.github.com/2010/09/01/importacao-feita.html"/>
   <updated>2010-09-01T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/09/01/importacao-feita</id>
   <content type="html">&lt;h1&gt;Importação Feita!&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;01 Setembro 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Já vi que vai realmente ser muito mais fácil de trabalhar assim. Importação feita. Menos de 6h gastas entre ideia, implementação, importação e esse post.&lt;/p&gt;
&lt;p&gt;Depois preciso avaliar a implementação de tags, comentários, etc. Mas isso fica pra depois mesmo. Estou bem satisfeito com o que tenho até agora. Tá muito fácil abrir o editor de textos, escrever, dar commit, push e pronto! Vou criar uma tarefa rake para criar o arquivo do post também, pois vai facilitar ainda mais.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Adicionado comentários e criador de posts</title>
   <link href="http://rafaeldx7.github.com/2010/09/01/Adicionado-coment--rios-e-criador-de-posts.html"/>
   <updated>2010-09-01T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/09/01/Adicionado-coment--rios-e-criador-de-posts</id>
   <content type="html">&lt;h1&gt;Adicionado comentários e criador de posts&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;01 . 09 . 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;E com mais algum pouco tempo de trabalho, temos comentários aqui no blog. Criei uma conta no &lt;a href=&quot;http://disqus.com&quot;&gt;&lt;span class=&quot;caps&quot;&gt;DISQUS&lt;/span&gt;&lt;/a&gt;, adicionei o código javascript necessário aqui e pronto. Recomendo esse &lt;a href=&quot;http://jekyllrb.com&quot;&gt;Jekyll&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;Como eu também gosto de conforto, implementei a criação do arquivo de post com uma tarefa rake. Só chegar no diretório do projeto e dar &lt;code&gt;rake&lt;/code&gt;. Ele vai pedir o título do post, criar o arquivo, e adicionar um layout básico pra eu começar a escrever. Fácil!&lt;/p&gt;
&lt;p&gt;Dei uma alterada no css também. Coisa leve.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Cansei do Blogger</title>
   <link href="http://rafaeldx7.github.com/2010/08/31/cansei-do-blogger.html"/>
   <updated>2010-08-31T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/08/31/cansei-do-blogger</id>
   <content type="html">&lt;h1&gt;Cansei do Blogger&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;31 Agosto 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Cansei do Blogger. Aquele editor estava me irritando e eu perdia a vontade de fazer novos posts. Pensei em mudar para o Tumblr, porém uma hora ou outra iria cansar dele também. Daí lembrei que o Github disponibiliza um subdomínio para cada usuário cadastrado. Está lá, é só usar. Junto com isso, descobri o excelente &lt;a href=&quot;http://github.com/mojombo/jekyll&quot;&gt;Jenkyll&lt;/a&gt; que é um gerador de site estático. Através de uma estrutura simples, ele gera as páginas html e pronto. Simples e com controle total. Do jeito que eu gosto.&lt;/p&gt;
&lt;p&gt;Preciso ver como importar meus antigos posts pra cá. Mas daqui a pouco dou um jeito nisso. Por enquanto, fico apenas com esse post mesmo. Tenho muito o que aprender com esse &lt;a href=&quot;http://github.com/mojombo/jekyll&quot;&gt;Jenkyll&lt;/a&gt; e já estou gostando muito do que estou vendo. Tenho também que dar um jeito de colocar comentários aqui. Comentários são legais, né?&lt;/p&gt;
&lt;p&gt;Agora é escrever o post no editor de textos, mandar pro Github e pronto: no ar!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Como saber qual o SO com Ruby?</title>
   <link href="http://rafaeldx7.github.com/2010/08/30/como-saber-qual-o-so-com-ruby-.html"/>
   <updated>2010-08-30T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/08/30/como-saber-qual-o-so-com-ruby-</id>
   <content type="html">&lt;h1&gt;Como saber qual o SO com Ruby?&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;30 Agosto 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Algumas vezes é interessante saber em qual sistema operacional o Ruby está sendo executado. Para isso existe a constante RUBY_PLATAFORM:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;$ irb&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;ruby-1.8.7-p299 &amp;gt; RUBY_PLATFORM&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;=&amp;gt; &amp;quot;i686-darwin10.4.0&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>OpenGEM ~ Veja o código e a doc de uma gem</title>
   <link href="http://rafaeldx7.github.com/2010/08/10/opengem-o-codigo-e-a-documentacao-de-uma-gem.html"/>
   <updated>2010-08-10T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/08/10/opengem-o-codigo-e-a-documentacao-de-uma-gem</id>
   <content type="html">&lt;h1&gt;OpenGEM ~ Veja o código e a doc de uma gem&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;10 Agosto 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Usando o &lt;a href=&quot;http://github.com/adamsanderson/open_gem&quot;&gt;OpenGEM&lt;/a&gt;, fica muito fácil ver a documentação e o código fonte de uma gem.&lt;/p&gt;
&lt;p&gt;Abre a documentação da gem rails no navegador:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;console&quot;&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; gem &lt;span class=&quot;nb&quot;&gt;read &lt;/span&gt;rails
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Abre o código fonte da gem rails no editor de textos padrão:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;console&quot;&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; gem open rails
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Sensacional para aprender sobre as gems e ler o que o código faz.&lt;/p&gt;
&lt;p&gt;Pra instalar o OpenGEM:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;console&quot;&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; gem install open_gem
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;E para saber mais:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;console&quot;&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; gem open --help
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>ASCIIcasts em Português</title>
   <link href="http://rafaeldx7.github.com/2010/08/09/asciicasts-em-portugues.html"/>
   <updated>2010-08-09T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/08/09/asciicasts-em-portugues</id>
   <content type="html">&lt;h1&gt;ASCIIcasts em Português&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;09 Agosto 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/_oEyf5UPMC4c/TGFRluemyZI/AAAAAAAACkU/OjkbqCakvuk/s1600/railscasts.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/_oEyf5UPMC4c/TGFRluemyZI/AAAAAAAACkU/OjkbqCakvuk/s320/railscasts.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;Muito conhecido no mundo Rails, o &lt;a href=&quot;http://railscasts.com/&quot;&gt;Railscasts&lt;/a&gt; é uma série de screencasts, produzido por Ryan Bates, onde ele sempre aborda assuntos bem recentes e interessantes. É um screencast “mão na massa”, mostrando código e resultado.&lt;br /&gt;Há algum tempo eu também conheci o excelente &lt;a href=&quot;http://asciicasts.com/&quot;&gt;ASCIIcasts&lt;/a&gt;, que é uma exata transcrição do &lt;a href=&quot;http://railscasts.com/&quot;&gt;Railscasts&lt;/a&gt;, para quem prefere ler o conteúdo. Também é útil para que o conteúdo seja indexado pelos mecanismos de busca.&lt;br /&gt;&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/_oEyf5UPMC4c/TGFRgwi_krI/AAAAAAAACkM/rcB9owMxxeU/s1600/143035940.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/_oEyf5UPMC4c/TGFRgwi_krI/AAAAAAAACkM/rcB9owMxxeU/s320/143035940.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Semana passada eu entrei em contato com o Eifion Bedford, o qual mantém o &lt;a href=&quot;http://asciicasts.com/&quot;&gt;ASCIIcasts&lt;/a&gt;, com o interesse de traduzir o material para português. Ele achou interessante e eu já traduzi os últimos dois episódios (224 e 225), que estão na &lt;a href=&quot;http://pt.asciicasts.com/&quot;&gt;área de episódios em português&lt;/a&gt;. Pretendo traduzir conforme os episódios vão sendo lançados. Espero que seja útil para muita gente.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-8562401198745305720?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Livros grátis pra quem trabalha com Web</title>
   <link href="http://rafaeldx7.github.com/2010/07/26/livros-gr--tis-pra-quem-trabalha-com-web.html"/>
   <updated>2010-07-26T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/07/26/livros-gr--tis-pra-quem-trabalha-com-web</id>
   <content type="html">&lt;h1&gt;Livros grátis pra quem trabalha com Web&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;26 July 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;h3&gt;&lt;a href=&quot;http://designingfortheweb.co.uk/&quot;&gt;A Practical Guide to Designing for the Web&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;&lt;br /&gt;&lt;a href=&quot;http://designingfortheweb.co.uk/&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://webdesignledger.com/wp-content/uploads/2010/07/web_design_books_6.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;A Practical Guide to Designing for the Web tem como objetivo ensinar técnicas para projetar seu Web site usando os princípios do design gráfico. Possui cinco partes, cada uma cobrindo um aspecto central do design gráfico: Primeiros passos, Pesquisa, Tipografia, Cor e Layout.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;a href=&quot;http://gettingreal.37signals.com/GR_por.php&quot;&gt;Getting Real&lt;/a&gt;&lt;/h3&gt;&lt;br /&gt;&lt;a href=&quot;http://gettingreal.37signals.com/GR_por.php&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://webdesignledger.com/wp-content/uploads/2010/07/web_design_books_2.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Getting Real são as filosofias de negócio, design, programação e marketing da 37signals – empresa onde o Ruby on Rails nasceu.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;a href=&quot;http://webtypography.net/&quot;&gt;The Elements of Typographic Style Applied to the Web&lt;/a&gt;&lt;/h3&gt;&lt;br /&gt;&lt;a href=&quot;http://webtypography.net/&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://webdesignledger.com/wp-content/uploads/2010/07/web_design_books_1.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;A fim de dissipar alguns dos mitos que cercam a tipografia na web, esse livro explica como usar as técnicas disponíveis em &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt; e &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt;&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;a href=&quot;http://jqfundamentals.com/&quot;&gt;jQuery Fundamentals&lt;/a&gt;&lt;/h3&gt;&lt;br /&gt;&lt;a href=&quot;http://jqfundamentals.com/&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://webdesignledger.com/wp-content/uploads/2010/07/web_design_books_8.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Escrito para ajudar a entender os fundamentos da biblioteca e ensinar a executar as tarefas básicas com jQuery.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;a href=&quot;http://www.webstyleguide.com/&quot;&gt;Web Style Guide&lt;/a&gt;&lt;/h3&gt;&lt;br /&gt;&lt;a href=&quot;http://www.webstyleguide.com/&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://webdesignledger.com/wp-content/uploads/2010/07/web_design_books_3.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Elogiado como o melhor volume de elementos clássicos do design web, Web Style Guide, agora em sua terceira edição, mantém uma ênfase em fundamentos.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;a href=&quot;http://universalusability.com/&quot;&gt;Access by Design&lt;/a&gt;&lt;/h3&gt;&lt;br /&gt;&lt;a href=&quot;http://universalusability.com/&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://webdesignledger.com/wp-content/uploads/2010/07/web_design_books_4.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Oferece diretrizes de usabilidade universal. E a versão online inclui exemplos e links para artigos e tutoriais.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;a href=&quot;http://book.airgid.com/&quot;&gt;Web Designer’s Success Guide&lt;/a&gt;&lt;/h3&gt;&lt;br /&gt;&lt;a href=&quot;http://book.airgid.com/&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://webdesignledger.com/wp-content/uploads/2010/07/web_design_books_5.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Web Designer’s Sucess Guide é o guia para começar seu próprio negócio freelance.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;a href=&quot;http://www.the-web-book.com/&quot;&gt;The Web Book&lt;/a&gt;&lt;/h3&gt;&lt;br /&gt;&lt;a href=&quot;http://www.the-web-book.com/&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://webdesignledger.com/wp-content/uploads/2010/07/web_design_books_7.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Contém todas as informações que você precisa para criar um site a partir do zero. Ele cobre tudo. Desde registar um nome de domínio e alugar um espaço de hospedagem, a criação de sua primeira página &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt;, até criação de aplicativos online completos com banco de dados (&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; e MySQL). Diz também uma forma de comercializar e promover o seu site, e como fazer dinheiro com isso.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;a href=&quot;http://diveintohtml5.org/&quot;&gt;Dive Into &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; 5&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;&lt;br /&gt;&lt;a href=&quot;http://diveintohtml5.org/&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://webdesignledger.com/wp-content/uploads/2010/07/web_design_books_9.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Sobre as funcionalidades do &lt;span class=&quot;caps&quot;&gt;HTML5&lt;/span&gt; e padrões.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;a href=&quot;http://www.uiaccess.com/accessucd/&quot;&gt;Just Ask: Integrating Accessibility Throughout Design&lt;/a&gt;&lt;/h3&gt;&lt;br /&gt;&lt;a href=&quot;http://www.uiaccess.com/accessucd/&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://webdesignledger.com/wp-content/uploads/2010/07/web_design_books_10.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Este livro vai ajudar você a compreender e aplicar os princípios para tornar seus produtos mais acessíveis.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;a href=&quot;http://www.uiaccess.com/understanding.html&quot;&gt;Understanding Web Accessibility&lt;/a&gt;&lt;/h3&gt;&lt;br /&gt;“Understanding Web Accessibility” é o capítulo 1 do livro Web Accessibility: Web Standards and Regulatory Compliance.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-2027649967708924608?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Rails - validates_associated</title>
   <link href="http://rafaeldx7.github.com/2010/07/23/rails---validates-associated.html"/>
   <updated>2010-07-23T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/07/23/rails---validates-associated</id>
   <content type="html">&lt;h1&gt;Rails &amp;#8211; validates_associated&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;23 July 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;O método de validação do Rails validates_associated não funciona como a maioria das pessoas espera. Essa validação só vai falhar se a associação existir e os objetos envolvidos na associação existirem e não forem válidos.&lt;/p&gt;
&lt;p&gt;Suponhamos os modelos Country e State dessa forma:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Country&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;has_many&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:states&lt;/span&gt;
  
  &lt;span class=&quot;n&quot;&gt;validates_presence_of&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:name&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;State&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;belongs_to&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:country&lt;/span&gt;
  
  &lt;span class=&quot;n&quot;&gt;validates_associated&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:country&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Agora no irb:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;console&amp;gt; state = State.create :name =&amp;gt; &amp;quot;RJ“&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; #&amp;lt;State id: 2, name: “RJ”, country_id: nil, created_at: “2010-07-23 19:52:52”, &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; updated_at: “2010-07-23 19:52:52”&amp;gt; &lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; state.valid?&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; true &lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; state.country = Country.new&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; #&amp;lt;Country id: nil, name: nil, created_at: nil, updated_at: nil&amp;gt; &lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; state.valid?&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; false &lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; state.country = Country.new :name =&amp;gt; &amp;quot;Brasil“&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; #&amp;lt;Country id: nil, name: “Brasil”, created_at: nil, updated_at: nil&amp;gt; &lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; state.valid?&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; true &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Repare que eu criei um state e salvei sem ele estar relacionado com algum country. Mesmo tendo o validates_associated no model State. Isso acontece porque eu não tinha um relacionamento inválido, então essa validação passa.&lt;/p&gt;
&lt;p&gt;Mas, quando eu criei um state e relacionei com um country inválido (sem nome), o validates_associated falhou. Logo depois eu relacionei o state a um country válido, o state passou a ser válido.&lt;/p&gt;
&lt;h2&gt;O detalhe que mata&lt;/h2&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;console&amp;gt; s = State.create :name =&amp;gt; &amp;quot;RJ“&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; #&amp;lt;State id: 9, name: “RJ”, country_id: nil, created_at: “2010-07-24 02:54:01”,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; updated_at: “2010-07-24 02:54:01”&amp;gt; &lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; s.valid?&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; true &lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; s.country&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; nil &lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; s.country_id&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; nil &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;console&amp;gt; Country.find_by_id 999999&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; nil&lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; s.country_id = 999999 # esse country não existe&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; 999999 &lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; s.country_id &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; 999999 &lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; s.valid?&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; true &lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;console&amp;gt; s.country&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; nil &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Agora veja. Criei um novo state e ele é válido, apesar do country ser nil e do country_id ser nil. Atribuí um id inexistente ao state.country_id. Ele continua sendo válido. Por quê?&lt;/p&gt;
&lt;p&gt;Se eu tiver um state.country_id = nil ou state.country_id com um id que não existe, quando eu chamo state.country o retorno será nil. E retorno nil na associação não faz o validates_associated falhar.&lt;/p&gt;
&lt;p&gt;Uma olhada no código do validates_associated esclarece:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;c1&quot;&gt;# File activemodel/lib/active_model/validations/associated.rb, line 35&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;validates_associated&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;attr_names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;configuration&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;default_error_messages&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:invalid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:on&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:save&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;configuration&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;attr_names&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;extract_options!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;validates_each&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;attr_names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;configuration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;attr_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;attr_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;configuration&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;unless&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_a?&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nil?&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;valid?&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;A condição para que a validação não falhe é &lt;code&gt;(r.nil? || r.valid?) &amp;amp;&amp;amp; v&lt;/code&gt;, justificando o comportamento que vimos.&lt;/p&gt;
&lt;p&gt;Ou seja, o validates_associated falha na única condição de termos um relacionamento com um objeto que não seja válido. Ele não garante que a associação existe. Se for necessário garantir que a associação existe, será preciso usar o validates_presence_of :country_id no model State. Mas isso também não é suficiente pra garantir que o country_id atribuído existe. Pra isso, é necessário fazer sua própria validação, a qual consiste basicamente no mesmo código do validates_associated alterando a condição para &lt;code&gt;!r.nil? &amp;amp;&amp;amp; r.valid? &amp;amp;&amp;amp; v&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Rails versão: 2.3.8&lt;br /&gt;
Referência:&lt;br /&gt;
&lt;a href=&quot;http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001404&quot;&gt;http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001404&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Ruby - zero é true</title>
   <link href="http://rafaeldx7.github.com/2010/06/24/ruby---zero----true.html"/>
   <updated>2010-06-24T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/06/24/ruby---zero----true</id>
   <content type="html">&lt;h1&gt;Ruby &amp;#8211; zero é true&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;24 Junho 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Em Ruby, os únicos valores &lt;strong&gt;&lt;em&gt;false&lt;/em&gt;&lt;/strong&gt;, em um teste lógico, são o próprio &lt;strong&gt;&lt;em&gt;false&lt;/em&gt;&lt;/strong&gt; e &lt;strong&gt;&lt;em&gt;nil&lt;/em&gt;&lt;/strong&gt;. O zero, que em muitas linguagens também é considerado &lt;strong&gt;&lt;em&gt;false&lt;/em&gt;&lt;/strong&gt;, em Ruby é &lt;strong&gt;&lt;em&gt;true&lt;/em&gt;&lt;/strong&gt;. Exemplo:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;$ irb&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;false&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;false&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;nil&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;false&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Fonte: &lt;a href=&quot;http://ruby-doc.org/docs/ProgrammingRuby/html/ref_c_trueclass.html&quot;&gt;Programming Ruby &amp;#8211; The Pragmatic Programmer&amp;#8217;s Guide﻿&lt;/a&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-1124103044048643784?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Rails - Qual ambiente?</title>
   <link href="http://rafaeldx7.github.com/2010/06/23/rails---qual-ambiente-.html"/>
   <updated>2010-06-23T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/06/23/rails---qual-ambiente-</id>
   <content type="html">&lt;h1&gt;Rails &amp;#8211; Qual ambiente?&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;23 Junho 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Para saber em que ambiente sua aplicação está sendo executada, é só fazer:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;ree-1.8.7-2010.02 &amp;gt; Rails.env&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; &amp;quot;development&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Até aí, nenhuma novidade. Mas quando é necessário colocar isso em um if, por exemplo, em vez de fazer:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;ree-1.8.7-2010.02 &amp;gt; Rails.env == &amp;quot;development&amp;quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Podemos ser mais elegantes, assim:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;ree-1.8.7-2010.02 &amp;gt; Rails.env.development?&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; true &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;ree-1.8.7-2010.02 &amp;gt; Rails.env.production?&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; =&amp;gt; false &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>GoogleCL</title>
   <link href="http://rafaeldx7.github.com/2010/06/19/googlecl.html"/>
   <updated>2010-06-19T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/06/19/googlecl</id>
   <content type="html">&lt;h1&gt;GoogleCL&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;19 Junho 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Pra quem gosta de usar linha de comando, o Google lançou uma ferramenta ótima: &lt;a link=&quot;http://code.google.com/p/googlecl/&quot;&gt;GoogleCL&lt;/a&gt;. Ele permite acessar diversos serviços pela linha de comando.&lt;br /&gt; &lt;br /&gt;&lt;a href=&quot;http://www.blogger.com/&quot; title=&quot;Blogger&quot;&gt;Blogger&lt;/a&gt;, &lt;a href=&quot;http://www.google.com/calendar&quot; title=&quot;Google Calendar&quot;&gt;Calendar&lt;/a&gt;, &lt;a href=&quot;http://googlesystem.blogspot.com/2008/09/google-contacts.html&quot; title=&quot;Google Contacts&quot;&gt;Contacts&lt;/a&gt;, &lt;a href=&quot;http://docs.google.com/&quot; title=&quot;Google Docs&quot;&gt;Docs&lt;/a&gt;, &lt;a href=&quot;http://picasaweb.google.com/&quot; title=&quot;Picasa Web Albums: free photo sharing from Google&quot;&gt;Picasa&lt;/a&gt; e &lt;a href=&quot;http://www.youtube.com/&quot; title=&quot;YouTube&quot;&gt;Youtube&lt;/a&gt; podem ser usados através do GoogleCL, que por sua vez usa o &lt;a href=&quot;http://code.google.com/p/gdata-python-client/&quot;&gt;gdata-python-client&lt;/a&gt;, que é um cliente pronto pra usar as APIs desses serviços.   &lt;br /&gt; &lt;br /&gt;Já estou usando pra fazer esse post. Espero que dê certo. Vou estudar mais e depois faço um post explicando como funciona.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-3783907130437382958?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Um gerador de dados falsos pro Rails</title>
   <link href="http://rafaeldx7.github.com/2010/06/14/um-gerador-de-dados-falsos-pro-rails.html"/>
   <updated>2010-06-14T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/06/14/um-gerador-de-dados-falsos-pro-rails</id>
   <content type="html">&lt;h1&gt;Um gerador de dados falsos pro Rails&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;14 Junho 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Um gerador de dados fakes é uma perfeita ajuda em testes ou para demonstrar um sistema já com alguns dados.&lt;br /&gt;Para resolver isso, encontrei a gem Forgery. Ela é muito fácil de usar:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;$ irb&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;meta meta_require meta_require_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&amp;quot;&lt;/span&gt;forgery&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Forgery&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Basic&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;password &lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&amp;quot;&lt;/span&gt;i1OFmtr9Iqqt&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Forgery&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Personal&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;gender&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&amp;quot;&lt;/span&gt;Male&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Forgery&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Personal&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;shirt_size&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&amp;quot;&lt;/span&gt;S&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Forgery&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Internet&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;email_address&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&amp;quot;&lt;/span&gt;aspencer@mymm.org&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Forgery&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Internet&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;user_name&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&amp;quot;&lt;/span&gt;jkennedy&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Forgery&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Monetary&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;formatted_money&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&amp;quot;&lt;/span&gt;$1.19&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Forgery&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;LoremIpsum&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;paragraphs&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&amp;quot;&lt;/span&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit&amp;#8230;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Para saber mais, é só ir no repositório: &lt;a href=&quot;http://github.com/sevenwire/forgery&quot;&gt;http://github.com/sevenwire/forgery﻿&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-6227855377509799022?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Agenda DojoRio</title>
   <link href="http://rafaeldx7.github.com/2010/05/27/agenda-dojorio.html"/>
   <updated>2010-05-27T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/05/27/agenda-dojorio</id>
   <content type="html">&lt;h1&gt;Agenda DojoRio&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;27 Maio 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Agora as pessoas poderão se manter atualizadas em meio a todas as programações organizadas pelo DojoRio. Uma agenda foi criada pro grupo se manter atualizado e poder convidar ainda mais pessoas.&lt;br /&gt;&lt;br /&gt;Essa agenda é pública e está no endereço http://bit.ly/dzLap1 ou abaixo:&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: courier, monospace; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;iframe frameborder=&quot;0&quot; height=&quot;300&quot; scrolling=&quot;no&quot; src=&quot;http://www.google.com/calendar/embed?mode=AGENDA&amp;height=300&amp;wkst=1&amp;hl=pt_BR&amp;bgcolor=%23FFFFFF&amp;src=ujuavsaq1b4m9p8isno70vmer0%40group.calendar.google.com&amp;color=%23060D5E&amp;ctz=America%2FSao_Paulo&quot; style=&quot;border: solid 1px #777;&quot; width=&quot;640&quot;&gt;&lt;/iframe&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: courier, monospace; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: courier, monospace; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-952391873609070724?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>DojoRio@Niterói</title>
   <link href="http://rafaeldx7.github.com/2010/05/25/dojorio-niter--i.html"/>
   <updated>2010-05-25T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/05/25/dojorio-niter--i</id>
   <content type="html">&lt;h1&gt;DojoRio@Niterói&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;25 Maio 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Na última quinta-feira eu participei do &lt;a href=&quot;http://codingdojo.org/&quot;&gt;Coding Dojo&lt;/a&gt; com o grupo do &lt;a href=&quot;http://dojorio.wordpress.com/&quot;&gt;DojoRio&lt;/a&gt; aqui de Niterói. A reunião acontece na &lt;span class=&quot;caps&quot;&gt;UFF&lt;/span&gt; e é sensacional. Coincidiu dos calouros aparecerem em massa e foi muito bom ver todos interagindo sem distinção de nível de conhecimento.&lt;br /&gt;&lt;br /&gt;Coding Dojo é uma verdadeira imersão em programação. Todo programador deveria participar desde o momento em que resolveu escrever a primeira linha de código.&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 12px; white-space: pre; text-align:center;&quot;&gt;&lt;object height=&quot;385&quot; width=&quot;480&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/qhAToHfF7gk&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x5d1719&amp;color2=0xcd311b&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;http://www.youtube.com/v/qhAToHfF7gk&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x5d1719&amp;color2=0xcd311b&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;480&quot; height=&quot;385&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Pra quem ainda não sabe o que é Coding Dojo, um vídeo que explica de forma rápida:&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: 'Lucida Grande'; font-size: 11px; white-space: pre-wrap; text-align:center;&quot;&gt;&lt;embed allowfullscreen=&quot;true&quot; allowscriptaccess=&quot;always&quot; id=&quot;VideoPlayback&quot; src=&quot;http://video.google.com/googleplayer.swf?docid=-9174018775255486687&amp;hl=en&amp;fs=true&quot; style=&quot;height: 326px; width: 400px;&quot; type=&quot;application/x-shockwave-flash&quot;&gt;&lt;/embed&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Entre pro grupo DojoRio:&lt;br /&gt;http://groups.google.com.br/group/dojo-rio&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-3642789133771984205?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Grandes obras</title>
   <link href="http://rafaeldx7.github.com/2010/03/31/grandes-obras.html"/>
   <updated>2010-03-31T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/03/31/grandes-obras</id>
   <content type="html">&lt;h1&gt;Grandes obras&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;31 Março 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://farm3.static.flickr.com/2439/4000108266_d4f8eb5876_d.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href=&quot;http://farm3.static.flickr.com/2439/4000108266_d4f8eb5876_d.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://farm3.static.flickr.com/2439/4000108266_d4f8eb5876_d.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;Não é porque é &amp;#8220;apenas&amp;#8221; a estrutura que não pode ter um bom acabamento. Uma boa obra tem todo o seu projeto bem elaborado e bem executado. Da estrutura aos detalhes de acabamento.&lt;br /&gt;&lt;br /&gt;Quando uma pessoa constrói algo, deve sempre avaliar o que está fazendo: um trabalho ou uma obra. &lt;br /&gt;&lt;br /&gt;Uma coisa é você parar pra redigir uma redação em uma prova qualquer. Coisa que você só fará quando necessário, pra alcançar um objetivo claro e definido.&lt;br /&gt;&lt;br /&gt;Outra coisa é redigir uma obra. Algo que vai ser referência. Que vai ser admirado, estudado, interpretado. Que vai marcar o tempo ou se tornar atemporal. &lt;br /&gt;&lt;br /&gt;A criação de uma obra não está desligada do objetivo de construção de algo que será utilizado de maneira prática. O Empire States Building, uma das mais imponentes construções de Nova York, é um bom exemplo. O arranha-céu mais alto do mundo por 41 anos, e a estrutura mais alta já feita pelo homem por 23 anos foi construído para ser um prédio comercial, onde espaços seriam alugados como escritório.&lt;br /&gt;&lt;br /&gt;Quem será que está construindo os arranha-céus da internet? Nesse mundo tão dinâmico, quem pensa em construções tão imponentes e tão sólidas? Será que podemos considerar que nossos Empire States virtuais são Twitter, Facebook, Orkut? Acho que dá pra parar e pensar um pouco sobre essas questões.&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: 'Trebuchet MS', sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Foto: &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: 'Trebuchet MS', sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://www.flickr.com/photos/pixagraphic/4000108266/&quot;&gt;Empire State Building &lt;span class=&quot;caps&quot;&gt;HDRI&lt;/span&gt; por pixagraphic&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: 'Trebuchet MS', sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-6247981966468132238?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Rails: find(nil)</title>
   <link href="http://rafaeldx7.github.com/2010/03/26/rails--find-nil-.html"/>
   <updated>2010-03-26T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/03/26/rails--find-nil-</id>
   <content type="html">&lt;h1&gt;Rails: find(nil)&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;26 Março 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Em alguns casos, pode ser necessário buscar um objeto pelo id e ter simplesmente um &lt;b&gt;nil&lt;/b&gt; caso não exista um objeto com o tal id.&lt;br /&gt;&lt;br /&gt;Se alguém tentar fazer:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;debit &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Debit&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;find&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;101010&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Verá o erro:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_plain&quot;&gt;&lt;span class=&quot;meta meta_paragraph meta_paragraph_text&quot;&gt;ActiveRecord::RecordNotFound: Couldn&amp;#8217;t find Debit with ID=101010&lt;br /&gt;       &lt;span class=&quot;meta meta_paragraph meta_paragraph_text&quot;&gt;from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1586:in `find_one&amp;#8217;&lt;/span&gt;&lt;br /&gt;        from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1569:in `find_from_ids&amp;#8217;&lt;br /&gt;        from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:616:in `find&amp;#8217;&lt;br /&gt;        from (irb):4&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Isso porque o método &lt;b&gt;find&lt;/b&gt; do &lt;b&gt;Active Record&lt;/b&gt; lança um &lt;b&gt;RecordNotFound Exception&lt;/b&gt; se não achar o que está procurando. O jeito é:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;  debit &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Debit&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;find&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;101010&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; e&lt;br /&gt;  debit &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;nil&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Mas&amp;#8230; se você for uma pessoa sagaz&amp;#8230; vai fazer:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;debit &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Debit&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;find_by_id&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;101010&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;E terá o seu lindo e esperado objeto ou nil, caso o objeto não for encontrado.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-217143380904052401?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Ruby: if e unless fluentes</title>
   <link href="http://rafaeldx7.github.com/2010/03/25/ruby--if-e-unless-fluentes.html"/>
   <updated>2010-03-25T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/03/25/ruby--if-e-unless-fluentes</id>
   <content type="html">&lt;h1&gt;Ruby: if e unless fluentes&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;25 Março 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Aproveitando uma mensagem do &lt;a href=&quot;http://twitter.com/rafaelss/status/11056573672&quot;&gt;@rafaelss&lt;/a&gt; no Twitter sobre o &lt;b&gt;unless&lt;/b&gt; em Ruby, tomei ânimo pra escrever sobre &lt;b&gt;if&lt;/b&gt; e &lt;b&gt;unless&lt;/b&gt;, coisa que eu já estava pensando faz algum tempo.&lt;br /&gt;&lt;br /&gt;Eu gosto do &lt;b&gt;unless&lt;/b&gt;! Foi uma das primeiras coisas que me chamou a atenção no Ruby. Vi que a linguagem tenta ser fluente no que está fazendo e vejo no &lt;b&gt;unless&lt;/b&gt; uma ajuda boa nesse sentido. Entretando, como em todo bom código, é necessário ter algum &amp;#8220;modo de pensar fluente&amp;#8221; no uso do &lt;b&gt;if&lt;/b&gt; e do &lt;b&gt;unless&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Rollback&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;unless&lt;/span&gt; payment&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;complete?&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;O código acima me parece muito mais fluente que:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Rollback&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby&quot;&gt;!&lt;/span&gt;payment&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;complete?&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Assim como:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;unless&lt;/span&gt; credit&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;save&lt;br /&gt;  &lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Rollback&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;É mais legal que:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby&quot;&gt;!&lt;/span&gt;credit&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;save&lt;br /&gt;  &lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Rollback&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Porém eu não gosto de usar &lt;b&gt;else&lt;/b&gt; com &lt;b&gt;unless&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;unless&lt;/span&gt; credit&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;save&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; error fix code&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; ok code&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Parece esquisito, quebrado, remendado. Pra usar o &lt;b&gt;else&lt;/b&gt; é melhor usar &lt;b&gt;if&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; credit&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;save&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; ok code&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; error fix code&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Mas repare bem que eu inverti a ordem do teste. Não é agradável ler algo como: Se não acontece alguma coisa senão acontece outra. Soa mal! Um exemplo mais real: Se não chover eu vou caminhar, senão eu vou ao cinema. Algo mais natural: Se chover eu vou ao cinema, senão vou caminhar. Podem achar frescura, mas passar 8 horas por dia lendo &amp;#8220;se não&amp;#8230; senão&amp;#8230;&amp;#8221; pode fazer alguém entrar numa escola com uma &lt;a href=&quot;http://pt.wikipedia.org/wiki/Uzi&quot;&gt;submetralhadora Uzi&lt;/a&gt; e matar todos os seus coleguinhas!&lt;br /&gt;&lt;br /&gt;Então, repetindo, caros leitores. Não é legal:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby&quot;&gt;!&lt;/span&gt;credit&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;save&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; error fix code&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; ok code&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Prefiram:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; credit&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;save&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; ok code&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; error fix code&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Outra coisa é testar se um valor é &lt;b&gt;nil&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;unless&lt;/span&gt; value&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;nil?&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; do something&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;É mais agradável:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; value&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; do something&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Tem o mesmo efeito, mas contribui para um mundo melhor.&lt;br /&gt;&lt;br /&gt;Quando temos múltiplas condições o unless também parece confuso:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby&quot;&gt;!&lt;/span&gt;valid? &lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby&quot;&gt;!&lt;/span&gt;beautiful?&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; do good thing&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Algo melhor:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; valid? &lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby&quot;&gt;and&lt;/span&gt; beautiful?&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; do good thing&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Estruturas condicionais bem escritas deveriam aumentar o salário de um programador. Isso contribui pro fácil entendimento da mensagem que será executada. Pra um processador não faz a menor diferença &amp;#8211; ou se fizer será mínima.&lt;br /&gt;&lt;br /&gt;Claro que o que parece bom pra uma pessoa pode não ser pra outra. Podem existir até discordâncias quanto ao que é mais fluente ou não. Mas existem certas coisas que confundem qualquer um numa primeira leitura. Isso sim deve ser evitado.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-7625322090434026913?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Ruby: %w(and or not && || !)</title>
   <link href="http://rafaeldx7.github.com/2010/03/23/ruby---w-and-or-not--amp--amp-------.html"/>
   <updated>2010-03-23T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/03/23/ruby---w-and-or-not--amp--amp-------</id>
   <content type="html">&lt;h1&gt;Ruby: %w(and or not &amp;amp;&amp;amp; || !)&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;23 Março 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Um pouco sobre esses operadores booleanos em Ruby.&lt;br /&gt;&lt;br /&gt;&amp;#8220;E&amp;#8221;&lt;br /&gt;&lt;br /&gt;Ambos os operadores, &amp;#8220;and&amp;#8221; e &amp;#8220;&amp;amp;&amp;amp;&amp;#8221;, avaliam como verdadeira a expressão onde os dois operandos são verdadeiros. O segundo operando só é avaliado caso o primeiro seja verdadeiro. Isso é conhecido como &lt;i&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Short-circuit_evaluation&quot;&gt;minimal evaluation ou short-circuit evaluation&lt;/a&gt;&lt;/i&gt;. A única diferença entre as duas formas é a precedência: &amp;#8220;&amp;amp;&amp;amp;&amp;#8221; tem precedência em relação a &amp;#8220;and&amp;#8221;.&lt;br /&gt;&lt;br /&gt;&amp;#8220;Ou&amp;#8221;&lt;br /&gt;&lt;br /&gt;Analogamente os operadores &amp;#8220;or&amp;#8221; e &amp;#8220;| |&amp;#8221; avaliam a expressão como verdadeira na qual um dos operandos é verdadeiro.  O segundo operando é avaliado somente no caso do primeiro ser falso. A única diferença entre eles está na precedência: &amp;#8220;| |&amp;#8221; tem precedência em relação a &amp;#8220;or&amp;#8221;.&lt;br /&gt;&lt;br /&gt;Por falar nisso, &amp;#8220;and&amp;#8221; e &amp;#8220;or&amp;#8221; tem a mesma precedência, entretanto &amp;#8220;&amp;amp;&amp;amp;&amp;#8221; tem uma precedência em relação a &amp;#8220;| |&amp;#8221;.&lt;br /&gt;&lt;br /&gt;&amp;#8220;Não&amp;#8221;&lt;br /&gt;&lt;br /&gt;&amp;#8220;not&amp;#8221; e &amp;#8220;!&amp;#8221; retornam o valor oposto do seu operando. A única diferença também é a precedência, pois &amp;#8220;!&amp;#8221; tem precedência em relação a &amp;#8220;not&amp;#8221;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Referência:&lt;br /&gt;&lt;a href=&quot;http://ruby-doc.org/docs/ProgrammingRuby/&quot;&gt;Programming Ruby &amp;#8211; The Pragmatic Programmer&amp;#8217;s Guide&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-4807351656973845594?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Gist na linha de comando</title>
   <link href="http://rafaeldx7.github.com/2010/03/10/gist-na-linha-de-comando.html"/>
   <updated>2010-03-10T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2010/03/10/gist-na-linha-de-comando</id>
   <content type="html">&lt;h1&gt;Gist na linha de comando&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;10 Março 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Uma maneira simples e rápida de usar o &lt;a href=&quot;http://gist.github.com/&quot;&gt;Gist&lt;/a&gt; é usando a &lt;a href=&quot;http://github.com/defunkt/gist&quot;&gt;gem gist criada pelo defunk no github&lt;/a&gt;. Ela fornece um script pra ser usado em linha de comando que permite facilmente o envio de arquivos para o &lt;a href=&quot;http://gist.github.com/&quot;&gt;Gist&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Pra quem ainda &lt;span class=&quot;Apple-style-span&quot; style=&quot;text-decoration: line-through;&quot;&gt;é retardado&lt;/span&gt; não conhece o Gist, ele é uma maneira simples de compartilhar arquivos. Todos os arquivos do Gist são repositórios git, logo eles são automaticamente versionados, clonáveis e possível de fazer fork. Sem burocracia.&lt;br /&gt;&lt;br /&gt;Pra usar a gem, tem que instalar:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ sudo gem install gist&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;E pra usar basta apenas executar o comando gist dessas maneiras:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ gist &amp;lt; file.txt&amp;lt;br /&amp;gt;$ echo secret | gist --private # or -p&amp;lt;br /&amp;gt;$ echo &quot;puts :hi&quot; | gist -t rb&amp;lt;br /&amp;gt;$ gist script.py&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Pra usar a sua conta do Github, é só fazer:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ git config --global github.user &quot;seu-github-username&quot;&amp;lt;br /&amp;gt;$ git config --global github.token &quot;seu-github-token&quot;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Pra descobrir o seu token, acesse sua conta no Github &amp;#8211; http://github.com/account&lt;br /&gt;&lt;br /&gt;Pra ver todas as opções, use:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$ gist -m&lt;/code&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-7132218002616413975?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Bash: executando o último comando</title>
   <link href="http://rafaeldx7.github.com/2010/01/26/bash--executando-o---ltimo-comando.html"/>
   <updated>2010-01-26T00:00:00-02:00</updated>
   <id>http://rafaeldx7.github.com/2010/01/26/bash--executando-o---ltimo-comando</id>
   <content type="html">&lt;h1&gt;Bash: executando o último comando&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;26 Janeiro 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;se você quer executar novamente o último comando completo, use:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;prompt&amp;gt; !!&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;isso é útil, por exemplo, se você esqueceu de colocar o sudo na frente do último comando. assim é necessário apenas fazer:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;prompt&amp;gt; apachectl stop&lt;br /&gt;This operation requires root.&lt;br /&gt;&lt;br /&gt;prompt&amp;gt; sudo !!&lt;br /&gt;sudo apachectl stop&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;muito simples.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-3900362206693152821?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Bash: último argumento do comando anterior</title>
   <link href="http://rafaeldx7.github.com/2010/01/26/bash----ltimo-argumento-do-comando-anterior.html"/>
   <updated>2010-01-26T00:00:00-02:00</updated>
   <id>http://rafaeldx7.github.com/2010/01/26/bash----ltimo-argumento-do-comando-anterior</id>
   <content type="html">&lt;h1&gt;Bash: último argumento do comando anterior&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;26 Janeiro 2010 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;se você executa, por exemplo:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;prompt&amp;gt; ls -la /usr/bin/vi&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;e agora vc quer executar o /usr/bin/vi. é só executar:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;prompt&amp;gt; !$&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;isso esquivale a fazer:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;prompt&amp;gt; /usr/bin/vi&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;pois o !$ insere na linha de comando o último argumento usado no comando anterior.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;outro exemplo:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;prompt&amp;gt; ls -la /etc/my.cnf&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;agora vc quer ver o conteúdo do arquivo /etc/my.cnf?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;prompt&amp;gt; cat !$&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;simples e fácil.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-3616874331294243962?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>PHP - Números preenchidos com zeros a esquerda</title>
   <link href="http://rafaeldx7.github.com/2009/12/16/php---n--meros-preenchidos-com-zeros-a-esquerda.html"/>
   <updated>2009-12-16T00:00:00-02:00</updated>
   <id>http://rafaeldx7.github.com/2009/12/16/php---n--meros-preenchidos-com-zeros-a-esquerda</id>
   <content type="html">&lt;h1&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; &amp;#8211; Números preenchidos com zeros a esquerda&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;16 Dezembro 2009 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;e vc precisa de números preenchidos com zeros a esquerda, o &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt; proporciona um jeito fácil de fazer isso:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_html text_html_basic&quot;&gt;&lt;span class=&quot;source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt; &lt;span class=&quot;support support_function support_function_formatted_print support_function_formatted_print_php&quot;&gt;printf&lt;/span&gt;(&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;%05d&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;, &amp;#8221;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_php&amp;quot;&amp;gt;-&lt;/span&gt;&lt;span class=&quot;constant constant_numeric constant_numeric_php&quot;&gt;654&lt;/span&gt;)&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Traduzindo a formatação 05d:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;0 – preencher com zeros a esquerda, se o número de caracteres é inferior ao requerido;&lt;br /&gt;5 – é o mínimo de caracteres requerido;&lt;br /&gt;d – trata o argumento inteiro como um decimal respeitando seu sinal.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A função printf escreve a string formatada direto na saída padrão. Se precisar jogar essa string em uma variável, use sprintf da mesma forma.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-8815929666032426866?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Magento dando erro no login</title>
   <link href="http://rafaeldx7.github.com/2009/11/17/magento-dando-erro-no-login.html"/>
   <updated>2009-11-17T00:00:00-02:00</updated>
   <id>http://rafaeldx7.github.com/2009/11/17/magento-dando-erro-no-login</id>
   <content type="html">&lt;h1&gt;Magento dando erro no login&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;17 Novembro 2009 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Magento 1.3.2.4 está apresentando um erro bem estranho: não permite login através de qualquer browser, apenas no Safari e Opera funciona. No Firefox, no Chrome e no IE aparece um erro como se os cookies estivessem desabilitados, mas verificando estava tudo ok.&lt;br /&gt;&lt;br /&gt;Pesquisei um pouco e encontrei uma solução no próprio fórum do Magento. Ele está com um bug em seu javascript que aparece quando o sistema está sendo executado no localhost.&lt;br /&gt;&lt;br /&gt;Pra funcionar use http://127.0.0.1 em vez de http://localhost e tudo funciona “normalmente”. Isso pode ser feito na instalação, quando é escolhido o host ou, se já estiver instalado, no admin (com um dos browsers que funciona) em System ›› Configuration ›› Web, trocando tudo que for localhost por 127.0.0.1.&lt;br /&gt;&lt;br /&gt;Coloquei o sistema em um subdomínio pra testar e não deu esse problema. Parece que é só com o localhost mesmo.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-6966912491213742588?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>MySQL: insert x insert ignore x replace</title>
   <link href="http://rafaeldx7.github.com/2009/10/22/mysql--insert-x-insert-ignore-x-replace.html"/>
   <updated>2009-10-22T00:00:00-02:00</updated>
   <id>http://rafaeldx7.github.com/2009/10/22/mysql--insert-x-insert-ignore-x-replace</id>
   <content type="html">&lt;h1&gt;MySQL: insert x insert ignore x replace&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;22 Outubro 2009 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Alguns detalhes que muitas vezes são ignorados podem facilitar muito a vida no MySQL.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 24px; font-weight: bold;&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Talvez o &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt;&lt;/span&gt; seja o segundo comando &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;SQL&lt;/span&gt;&lt;/span&gt; mais conhecido, perdendo apenas para o &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;SELECT&lt;/span&gt;&lt;/span&gt;. Ele insere novos registros em uma tabela existente. Caso o &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt;&lt;/span&gt; esteja tentando inserir um registro que tenha a mesma chave primária (primary key) ou índice único (unique index) de outro já existente na tabela, ocorre um erro chamado &lt;strong&gt;erro de chave duplicada (duplicate-key error)&lt;/strong&gt; e a execução é abortada. &lt;br /&gt;&lt;br /&gt;Se esse erro ocorrer no meio de um script &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;SQL&lt;/span&gt;&lt;/span&gt;, a execução do script é abortada.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 24px; font-weight: bold;&quot;&gt;&lt;span class=&quot;caps&quot;&gt;REPLACE&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Funciona exatamente como o &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt;&lt;/span&gt;, porém se o registro que está sendo inserido tem a mesma chave primária (primary key) ou índice único (unique index) de outro já existente na tabela, esse registro já existente é apagado antes do novo ser inserido. E não ocorre erro.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;IGNORE&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;A cláusula &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;IGNORE&lt;/span&gt;&lt;/span&gt; altera um pouco o comportamento do &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt;&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;Se o registro que está sendo inserido tem a mesma chave primária (primary key) ou índice único (unique index) de outro já existente na tabela, o &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;IGNORE&lt;/span&gt;&lt;/span&gt; é ignorado e não ocorre erro.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tentativas de inserir registros com valores inválidos não causam erros. Os valores serão ajustados para valores mais aceitáveis e inseridos. Warnings são produzidos, mas a execução não é abortada.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Resumindo&lt;/h2&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; white-space: pre;&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;DELETE&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;FROM&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_sql&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;INTO&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt; (&lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;id`&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;name`&lt;/span&gt;) &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_II keyword_other_DML_II_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt; (&lt;span class=&quot;constant constant_numeric constant_numeric_sql&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;&amp;#8220;&lt;/span&gt;Adriana&amp;#8221;&lt;/span&gt;);&lt;br /&gt;&lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;INTO&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt; (&lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;id`&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;name`&lt;/span&gt;) &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_II keyword_other_DML_II_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt; (&lt;span class=&quot;constant constant_numeric constant_numeric_sql&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;&amp;#8220;&lt;/span&gt;Pedro&amp;#8221;&lt;/span&gt;);&lt;br /&gt;&lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;INTO&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt; (&lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;id`&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;name`&lt;/span&gt;) &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_II keyword_other_DML_II_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt; (&lt;span class=&quot;constant constant_numeric constant_numeric_sql&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;&amp;#8220;&lt;/span&gt;Rafael&amp;#8221;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;O primeiro &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt;&lt;/span&gt; será executado, o segundo dará erro e a execução será abortada (pois já foi inserido um registro com id = 1), o terceiro nem será executado.&lt;br /&gt;&lt;br /&gt;Resultado:&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;ins&gt;&lt;del&gt;-&lt;/del&gt;-&lt;/ins&gt;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;-&lt;ins&gt;&lt;br /&gt;| id | name    |&lt;br /&gt;&lt;/ins&gt;&amp;#8212;&amp;#8212;&lt;ins&gt;&lt;del&gt;-&lt;/del&gt;&amp;#8212;&amp;#8212;&amp;#8212;&lt;/ins&gt;&lt;br /&gt;|  1 | Adriana |&lt;br /&gt;&lt;ins&gt;&lt;del&gt;-&lt;/del&gt;-&lt;/ins&gt;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;-&lt;ins&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_sql&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;DELETE&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;FROM&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt;;&lt;br /&gt;&lt;span class=&quot;caps&quot;&gt;REPLACE&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt; (&lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;id`&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;name`&lt;/span&gt;) &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_II keyword_other_DML_II_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt; (&lt;span class=&quot;constant constant_numeric constant_numeric_sql&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;&amp;#8220;&lt;/span&gt;Adriana&amp;#8221;&lt;/span&gt;);&lt;br /&gt;&lt;span class=&quot;caps&quot;&gt;REPLACE&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt; (&lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;id`&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;name`&lt;/span&gt;) &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_II keyword_other_DML_II_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt; (&lt;span class=&quot;constant constant_numeric constant_numeric_sql&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;&amp;#8220;&lt;/span&gt;Pedro&amp;#8221;&lt;/span&gt;);&lt;br /&gt;&lt;span class=&quot;caps&quot;&gt;REPLACE&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt; (&lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;id`&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;name`&lt;/span&gt;) &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_II keyword_other_DML_II_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt; (&lt;span class=&quot;constant constant_numeric constant_numeric_sql&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;&amp;#8220;&lt;/span&gt;Rafael&amp;#8221;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;O primeiro &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;REPLACE&lt;/span&gt;&lt;/span&gt; será executado inserindo normalmente o registro como o &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt;&lt;/span&gt; faria. O segundo apagará o registro com id = 1 e adicionará outro registro com id = 1 sem erros. O terceiro &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;REPLACE&lt;/span&gt;&lt;/span&gt; também será executado normalmente.&lt;br /&gt;&lt;br /&gt;Resultado:&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;/ins&gt;&amp;#8212;&amp;#8212;&lt;ins&gt;&lt;del&gt;-&lt;/del&gt;&amp;#8212;&amp;#8212;-&lt;/ins&gt;&lt;br /&gt;| id | name   |&lt;br /&gt;&lt;ins&gt;&lt;del&gt;-&lt;/del&gt;-&lt;/ins&gt;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;&lt;ins&gt;&lt;br /&gt;|  1 | Pedro  |&lt;br /&gt;|  2 | Rafael |&lt;br /&gt;&lt;/ins&gt;&amp;#8212;&amp;#8212;&lt;ins&gt;&lt;del&gt;-&lt;/del&gt;&amp;#8212;&amp;#8212;-&lt;/ins&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_sql&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;DELETE&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;FROM&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt;;&lt;br /&gt;&lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;IGNORE&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;INTO&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt; (&lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;id`&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;name`&lt;/span&gt;) &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_II keyword_other_DML_II_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt; (&lt;span class=&quot;constant constant_numeric constant_numeric_sql&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;&amp;#8220;&lt;/span&gt;Adriana&amp;#8221;&lt;/span&gt;);&lt;br /&gt;&lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;IGNORE&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;INTO&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt; (&lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;id`&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;name`&lt;/span&gt;) &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_II keyword_other_DML_II_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt; (&lt;span class=&quot;constant constant_numeric constant_numeric_sql&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;&amp;#8220;&lt;/span&gt;Pedro&amp;#8221;&lt;/span&gt;);&lt;br /&gt;&lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;IGNORE&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;INTO&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;table`&lt;/span&gt; (&lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;id`&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_backtick string_quoted_other_backtick_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;`&lt;/span&gt;name`&lt;/span&gt;) &lt;span class=&quot;keyword keyword_other keyword_other_DML keyword_other_DML_II keyword_other_DML_II_sql&quot;&gt;&lt;span class=&quot;caps&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt; (&lt;span class=&quot;constant constant_numeric constant_numeric_sql&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_sql&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_sql&quot;&gt;&amp;#8220;&lt;/span&gt;Rafael&amp;#8221;&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;O primeiro &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;IGNORE&lt;/span&gt;&lt;/span&gt; vai inserir o registro exatamente como o &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt;&lt;/span&gt; sozinho faria. O segundo vai tentar inserir outro registro, mas como a chave está duplicada, será ignorado sem erros. O terceiro &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;IGNORE&lt;/span&gt;&lt;/span&gt; também será executado normalmente.&lt;br /&gt;&lt;br /&gt;Resultado:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;ins&gt;&lt;del&gt;-&lt;/del&gt;-&lt;/ins&gt;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;-&lt;ins&gt;&lt;br /&gt;| id | name    |&lt;br /&gt;&lt;/ins&gt;&amp;#8212;&amp;#8212;&lt;ins&gt;&lt;del&gt;-&lt;/del&gt;&amp;#8212;&amp;#8212;&amp;#8212;&lt;/ins&gt;&lt;br /&gt;|  1 | Adriana |&lt;br /&gt;|  2 | Rafael  |&lt;br /&gt;&lt;ins&gt;&lt;del&gt;-&lt;/del&gt;-&lt;/ins&gt;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;-+&lt;br /&gt;&lt;/pre&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-1383470475462483525?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>git svn switch relocate</title>
   <link href="http://rafaeldx7.github.com/2009/08/24/git-svn-switch-relocate.html"/>
   <updated>2009-08-24T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2009/08/24/git-svn-switch-relocate</id>
   <content type="html">&lt;h1&gt;git svn switch relocate&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;24 Agosto 2009 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #111111; font-family: Georgia, sans-serif; font-size: 15px; line-height: 25px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;quando o repositório svn o qual foi feito o clone com o git-svn é movido, é preciso fazer alguns ajustes no git-svn pra poder continuar usando sem problemas. algo como um “svn switch—relocate” pra quem já está acostumado com o svn.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;quem está acostumado com o git e conhece o arquivo .git/config pensa logo em alterar o valor da “url” em “svn-remote”. o problema é que somente isso não funciona. alguns passos devem ser seguidos:&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;- alterar o arquivo .git/config, com a nova svn-remote url do svn;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;- executar um “git svn fetch” pra pegar a última revisão do svn. um detalhe importante: tem que vir alguma alteração do svn pra poder funcionar;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;- alterar a svn-remote url para a url antiga;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;- executar “git svn rebase &lt;del&gt;l” pra fazer um rebase local com as alterações que o fetch pegou. por isso que o fetch tem que trazer alguma alteração, senão o rebase não faz nada;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;/del&gt; alterar novamente a svn-remote url pra nova url do svn;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;- executar “git svn rebase”. isso deve funcionar sem erros agora. e a partir daí já se consegue dar “git svn dcommit” sem problemas para o novo repositório svn.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;referência: &lt;a href=&quot;http://git.or.cz/gitwiki/GitSvnSwitch&quot; style=&quot;color: #111111; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: underline;&quot;&gt;http://git.or.cz/gitwiki/GitSvnSwitch&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-5259362798360360418?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Configuração de upload em PHP</title>
   <link href="http://rafaeldx7.github.com/2009/06/25/configura----o-de-upload-em-php.html"/>
   <updated>2009-06-25T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2009/06/25/configura----o-de-upload-em-php</id>
   <content type="html">&lt;h1&gt;Configuração de upload em &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;25 Junho 2009 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;O programador não pode esquecer de algumas coisas quando vai trabalhar com upload de arquivos em &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;. Principalmente as diretivas do php.ini.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;As que ninguém esquece:&lt;/h2&gt;&lt;br /&gt;&lt;a href=&quot;http://us3.php.net/manual/pt_BR/ini.core.php#ini.upload-max-filesize&quot;&gt;upload_max_filesize&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;define qual o tamanho máximo permitido por arquivo. o valor padrão é 2 megas. se o arquivo exceder esse limite, $&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;FILES&lt;/span&gt;[&amp;#8220;file&amp;#8221;][&amp;#8220;error&amp;#8221;] chega com valor 1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://us3.php.net/manual/pt_BR/ini.core.php#ini.file-uploads&quot;&gt;file_uploads&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;define se é permitido o upload de arquivos. o valor padrão é On.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://us3.php.net/manual/pt_BR/ini.core.php#ini.upload-tmp-dir&quot;&gt;upload_tmp_dir&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;define o diretório temporário usado para guardar os arquivos de upload. o usuário que está executando o web script (em geral, o mesmo usuário do Web Server) deve ter permissão de escrita nesse diretório. se não for especificado, será usado o diretório temporário padrão do sistema.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;O que &lt;del&gt;quase&lt;/del&gt; ninguém lembra:&lt;/h2&gt;&lt;br /&gt;&lt;a href=&quot;http://us3.php.net/manual/pt_BR/ini.core.php#ini.post-max-size&quot;&gt;post_max_size&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;muito importante! define o tamanho máximo dos dados enviados via &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt;&lt;/span&gt;. isso afeta diretamente o upload de arquivos. esse valor deve &lt;strong&gt;sempre&lt;/strong&gt; ser maior que upload_max_filesize! o valor padrão é 8 megas.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;se o tamanho de dados exceder o valor de post_max_size, $&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt; e $&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;FILES&lt;/span&gt; chegarão vazios. e por isso &lt;del&gt;&lt;/del&gt;&lt;br /&gt;eu&lt;br /&gt;muita gente&lt;br /&gt;fica horas pra descobrir porque consegue fazer upload de arquivos pequenos mas não consegue com arquivos grandes. não dá erro, o arquivo simplesmente não chega. diferente do que acontece quando o arquivo excede apenas o upload_max_filesize.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://us3.php.net/manual/pt_BR/ini.core.php#ini.memory-limit&quot;&gt;memory_limit&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;define a quantidade máxima de memória que o script pode alocar. isso também afeta upload de arquivos. o manual do &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt; fala que memory_limit deve ser maior que post_max_size, mas eu mesmo já consegui fazer upload de arquivos maiores que o valor configurado nessa diretiva. vai entender! valor padrão: 128 megas.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;observação importante: todas essas diretivas que definem tamanho recebem o valor em bytes. porém, como o &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt; tem a péssima mania de querer fazer tudo ao mesmo tempo, pode ser usado uma notação mais amigável: K (pra Kilobyte), M (pra Megabyte) and G (pra Gigabyte). por exemplo: 1K ao invés de 1024. isso só vale dentro do php.ini.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;exemplo prático do uso das diretivas acima. no php.ini:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_git-config&quot;&gt;&lt;span class=&quot;comment comment_line comment_line_semi-colon comment_line_semi-colon_git-config&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_git-config&quot;&gt;;&lt;/span&gt; Maximum allowed size for uploaded files.&lt;br /&gt;&lt;/span&gt;upload_max_filesize = 100M&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_semi-colon comment_line_semi-colon_git-config&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_git-config&quot;&gt;;&lt;/span&gt; Whether to allow &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt; file uploads.&lt;br /&gt;&lt;/span&gt;file_uploads = On&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_semi-colon comment_line_semi-colon_git-config&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_git-config&quot;&gt;;&lt;/span&gt; Temporary directory for &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt; uploaded files (will use system default if not specified).&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_semi-colon comment_line_semi-colon_git-config&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_git-config&quot;&gt;;&lt;/span&gt; upload_tmp_dir =&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_semi-colon comment_line_semi-colon_git-config&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_git-config&quot;&gt;;&lt;/span&gt; Maximum size of &lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt; data that &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; will accept.&lt;br /&gt;&lt;/span&gt;post_max_size = 128M&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_semi-colon comment_line_semi-colon_git-config&quot;&gt;&lt;/em&gt;comment&lt;/em&gt;git-config&amp;quot;&amp;gt;;&lt;/span&gt; Maximum amount of memory a script may consume (8MB)&lt;br /&gt;&lt;/span&gt;memory&lt;/em&gt;limit = 256M&lt;/span&gt;&lt;/pre&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-5701874652396569899?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>usando git na dreamhost</title>
   <link href="http://rafaeldx7.github.com/2009/01/03/usando-git-na-dreamhost.html"/>
   <updated>2009-01-03T00:00:00-02:00</updated>
   <id>http://rafaeldx7.github.com/2009/01/03/usando-git-na-dreamhost</id>
   <content type="html">&lt;h1&gt;usando git na dreamhost&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;03 Janeiro 2009 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;comecei a usar o Git no final do ano passado. durante todo o ano de 2008 vi muita gente migrando de svn pra Git e quis aprender o que essa ferramenta tinha de tão boa. realmente ela é muito interessante e sua característica principal é ser um sistema de controle de versões distribuído. diferente do svn, não existe dar commit no repositório remoto, todo commit é feito no repositório local e, caso o usuário queira, os vários commits são enviados para o repositório remoto.&lt;br /&gt;&lt;br /&gt;ainda sou bem iniciante no Git e nada melhor pra aprender do que a prática. por isso resolvi colocar o dx7lab no Git pra de fato começar a trabalhar com ele. então, se eu fizer tudo errado e o blog sair do ar, conto com a compreensão de todos :P&lt;br /&gt;&lt;br /&gt;como uso a dreamhost, quis colocar um repositório lá pra já começar a trabalhar. como disse, sou iniciante no Git, não sei se fiz da melhor forma, mas estou tendo os resultados esperados. &lt;br /&gt;&lt;br /&gt;&lt;h3&gt;configurando o repositório remoto na dreamhost&lt;/h3&gt;&lt;br /&gt;na dreamhost já tem o git instalado, então é só configurar o repositório remoto. pra isso executei, na minha pasta home, os comandos abaixo:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;br /&amp;gt;$ mkdir &amp;lt;nome_do_repositorio_remoto&amp;gt; &amp;lt;br /&amp;gt;$ cd &amp;lt;nome_do_repositorio_remoto&amp;gt;&amp;lt;br /&amp;gt;$ git --bare init&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;assim criamos e entramos no diretório que será o repositório remoto. logo depois iniciamos esse repositório com a opção—bare.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;criando o repositório local&lt;/h3&gt;pra isso é só entrar no diretório do seu projeto e executar:&lt;br /&gt;&lt;code&gt;&amp;lt;br /&amp;gt;$ git init&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;depois disso, dê commit em todo o projeto.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;configurando o repositório local para acessar o remoto&lt;/h3&gt;&lt;code&gt; $ git remote add &amp;lt;nome_do_repositorio_remoto&amp;gt; &amp;lt;br /&amp;gt;ssh://&amp;lt;usuario&amp;gt;@&amp;lt;endereço_IP_ou_host&amp;gt;/~/&amp;lt;diretorio do repositorio remoto&amp;gt;&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;assim seu repositório local está pronto pra acessar o remoto na dreamhost. caso vc tenha errado esse comando, pode editar diretamente o arquivo .git/config dentro do seu projeto local.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;enviar o repositório local para o remoto&lt;/h3&gt;&lt;code&gt; $ git push --all &amp;lt;nome_do_repositorio_remoto&amp;gt;&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;assim vc enviou todo o projeto pro repositório remoto na dreamhost. vc poderá trabalhar normalmente e sempre que quiser enviar o código pra lá:&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;code&gt; $ git push &amp;lt;nome_do_repositorio_remoto&amp;gt;&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;criando um clone do repositório remoto&lt;/h3&gt;&lt;code&gt; $ git clone ssh://&amp;lt;usuario&amp;gt;@&amp;lt;endereço_IP_ou_host&amp;gt;/~/&amp;lt;diretorio do repositorio remoto&amp;gt;&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;vc tem todas as facilidades que o git oferece usando os recursos da dreamhost sem nenhum problema. acredito que esse procedimento deve funcionar em qualquer host compartilhado onde há acesso ssh e git instalado. e ainda que não tenha git instalado, vc pode tentar instalá-lo na home do seu usuário.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;instalando o git no seu servidor compartilhado&lt;/h3&gt;isso só vai funcionar se vc tiver espaço no servidor e tiver o mínimo de privilégios pra executar os comandos necessários na sua /home/&lt;usuario&gt;:&lt;br /&gt;&lt;code&gt;&amp;lt;br /&amp;gt;$ wget http://kernel.org/pub/software/scm/git/git-1.6.1.tar.gz&amp;lt;br /&amp;gt;$ tar zxvf git-1.6.1.tar.gz&amp;lt;br /&amp;gt;$ mkdir usr&amp;lt;br /&amp;gt;$ cd git-1.6.1&amp;lt;br /&amp;gt;$ ./configure --prefix=/home/&amp;lt;usuario&amp;gt;/usr&amp;lt;br /&amp;gt;$ make &amp;amp;&amp;amp; make install&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;os binários do Git estarão instalados no seu diretório /home/&lt;usuario&gt;/usr/bin/&lt;br /&gt;&lt;br /&gt;divirta-se!&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-8918805619647751049?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>PHP Puro e Limpo!</title>
   <link href="http://rafaeldx7.github.com/2008/12/19/php-puro-e-limpo-.html"/>
   <updated>2008-12-19T00:00:00-02:00</updated>
   <id>http://rafaeldx7.github.com/2008/12/19/php-puro-e-limpo-</id>
   <content type="html">&lt;h1&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; Puro e Limpo!&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;19 Dezembro 2008 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;Gostaria imensamente de saber o motivo que leva a todos os livros de &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/a&gt; a implementar exemplos totalmente horrorosos e mal estruturados.&lt;br /&gt;&lt;br /&gt;Eu já fui numa livraria especializada em livros técnicos com o objetivo exclusivo de procurar um livro bom em &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/a&gt;. Um livro que mostrasse exemplos e abrisse a mente do futuro programador não só pra nova linguagem, mas também pra uma boa prática de programação. Não encontrei nenhum. Pilhas de livros, do básico ao avançado, do mais barato ao mais caro, nacionais, importados, traduzidos. Olhei vários. Não encontrei nenhum que de fato faça com que o estudante tenha de cara uma boa abordagem de maneira simples. Se você conhecer algum, me indique. Do que estou falando? Disto:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_session support_function_session_php&quot;&gt;session_start&lt;/span&gt;()&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_php&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_php&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;empty&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_global variable_other_global_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt;&lt;/span&gt;)) {&lt;br /&gt;  &lt;span class=&quot;variable variable_other variable_other_global variable_other_global_safer variable_other_global_safer_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;SESSION&lt;/span&gt;&lt;/span&gt;[&lt;span class=&quot;support support_function support_function_var support_function_var_php&quot;&gt;var_export&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_global variable_other_global_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt;&lt;/span&gt;[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;note&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;], &amp;#8221;constant constant_language constant_language_php&amp;quot;&amp;gt;true&lt;/span&gt;)] &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_global variable_other_global_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt;&lt;/span&gt;[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;note&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_php&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;variable variable_other variable_other_global variable_other_global_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt;&lt;/span&gt;[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;Enviar&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;] &amp;#8221;keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_php&amp;quot;&amp;gt;==&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;Limpar Notas&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;)&lt;br /&gt;    &amp;#8221;variable variable_other variable_other_global variable_other_global_safer variable_other_global_safer_php&amp;quot;&amp;gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;SESSION&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;meta meta_array meta_array_php&quot;&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_begin punctuation_definition_array_begin_php&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_end punctuation_definition_array_end_php&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;center&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;h1&gt;Lista de Notas&lt;/h1&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;h2&gt;Exemplo de &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; bem feito&lt;/h2&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;h3&gt;Exemplo de como fazer um site em php bem feito sem usar uma linguagem de template&lt;/h3&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;p&gt;Esse site é apenas um exemplo. Não tenho o compromisso aqui de fazer um html perfeito ou&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;uma programação impecável. Quero apenas demonstrar que dá pra fazer &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; direito sem apelação!&lt;/p&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;hr /&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&amp;lt;form method=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt; action=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_string keyword_operator_string_php&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;php&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;Digite uma nota:&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&amp;lt;input type=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;note&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&amp;lt;input type=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;submit&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;Enviar&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt; value=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;Enviar&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&amp;lt;input type=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;submit&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;Enviar&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt; value=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;Limpar&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;Notas&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;/form&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;hr /&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;h4&gt;Notas gravadas&lt;/h4&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&amp;lt;hr width=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_numeric constant_numeric_php&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_php&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;ul&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_php&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_php&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;empty&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_global variable_other_global_safer variable_other_global_safer_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;SESSION&lt;/span&gt;&lt;/span&gt;)) {&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_php&quot;&gt;foreach&lt;/span&gt; (&lt;span class=&quot;variable variable_other variable_other_global variable_other_global_safer variable_other_global_safer_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;SESSION&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_php&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;note&lt;/span&gt;) {&lt;br /&gt;    &lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;li&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;keyword keyword_operator keyword_operator_string keyword_operator_string_php&amp;quot;&amp;gt;.&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;note&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_string keyword_operator_string_php&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;/li&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;/ul&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&amp;lt;hr width=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_numeric constant_numeric_php&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_php&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;small&gt;&amp;lt;a href=&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;constant constant_other constant_other_php&quot;&gt;http&lt;/span&gt;:&lt;span class=&quot;comment comment_line comment_line_double-slash comment_line_double-slash_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_php&quot;&gt;//&lt;/span&gt;dx7lab.com&amp;quot;&amp;gt;Dx7lab&lt;/a&gt;&lt;/small&gt;&amp;quot;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&lt;/center&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Todos concordam que isso é horrível, péssimo e não serve pra fazer nenhum sistema decente, certo? Código &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; misturado com &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt; que chega a ser ilegível. &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;LIXO&lt;/span&gt;&lt;/span&gt;! Livros de mais de 300 páginas com exemplos assim, desse tipo. É quase inacreditável. Vamos imaginar um bom conhecedor de &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt; querendo aprender a programar. Ele olharia isso e desistiria imediatamente de &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;. Coisas assim nos levam a concluir que &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; não presta pra escrever código organizado e limpo. Mas isso não é verdade!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Alguns livros de um nível mais intermediário chegam a falar nas famosas linguagens de template. &lt;a href=&quot;http://www.smarty.net/&quot;&gt;Smarty&lt;/a&gt;, &lt;a href=&quot;http://www.tinybutstrong.com/&quot;&gt;TinyButStrong&lt;/a&gt;, entre outras. Os mais avançados chegam a criar uma estrutura complexa pra encapsular o &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt; e criar uma view mais limpa. Tudo bem, mas isso não é necessário. Os autores que escrevem pra iniciantes podem argumentar dizendo que não querem inserir ainda mais complexidade no início do aprendizado. Concordo! Mas não precisa fazer nem uma coisa nem outra. Sinceramente? Eu não gosto dessas linguagens de template. Já usei algumas mas elas não fazem nada que não dê pra fazer simplesmente usando a linguagem. Dá pra fazer Código em &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; &lt;span class=&quot;caps&quot;&gt;PURO&lt;/span&gt; e &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;LIMPO&lt;/span&gt;&lt;/span&gt;! Por mais inédito que isso possa parecer. Usando coisas básicas da linguagem, que geralmente os livros abordam logo no início.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Abaixo está um exemplo que faz a mesma coisa que o código acima, mas de uma maneira limpa. Teremos 2 arquivos, um para o template – que será chamado template.tpl – e outro para o código &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; puro – chamado index.php.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Vejamos o template.tpl:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_html text_html_basic&quot;&gt;&lt;span class=&quot;meta meta_tag meta_tag_sgml meta_tag_sgml_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;!&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_sgml meta_tag_sgml_doctype meta_tag_sgml_doctype_html&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_doctype entity_name_tag_doctype_html&quot;&gt;&lt;span class=&quot;caps&quot;&gt;DOCTYPE&lt;/span&gt;&lt;/span&gt; html &lt;span class=&quot;caps&quot;&gt;PUBLIC&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_doctype string_quoted_double_doctype_identifiers-and-DTDs string_quoted_double_doctype_identifiers-and-DTDs_html&quot;&gt;&amp;#8220;-//W3C//&lt;span class=&quot;caps&quot;&gt;DTD&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;XHTML&lt;/span&gt; 1.0 Transitional//EN&amp;#8221;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_doctype string_quoted_double_doctype_identifiers-and-DTDs string_quoted_double_doctype_identifiers-and-DTDs_html&quot;&gt;&amp;#8220;http://www.w3.org/TR/xhtml1/&lt;span class=&quot;caps&quot;&gt;DTD&lt;/span&gt;/xhtml1-transitional.dtd&amp;#8221;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_structure meta_tag_structure_any meta_tag_structure_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_structure entity_name_tag_structure_any entity_name_tag_structure_any_html&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;xmlns&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;http://www.w3.org/1999/xhtml&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;xml:lang&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;en&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;lang&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;en&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_structure meta_tag_structure_any meta_tag_structure_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_structure entity_name_tag_structure_any entity_name_tag_structure_any_html&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;http-equiv&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;Content-Type&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;content&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;text/html; charset=&lt;span class=&quot;caps&quot;&gt;UTF&lt;/span&gt;-8&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Exemplo de &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; bem feito&lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_structure meta_tag_structure_any meta_tag_structure_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_structure entity_name_tag_structure_any entity_name_tag_structure_any_html&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_structure meta_tag_structure_any meta_tag_structure_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_structure entity_name_tag_structure_any entity_name_tag_structure_any_html&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;center&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Lista de Notas&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h2&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Exemplo de &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; bem feito&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h2&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Exemplo de como fazer um site em php bem feito sem usar uma linguagem de template&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Esse site é apenas um exemplo. Não tenho o compromisso aqui de fazer um html perfeito ou&lt;br /&gt;       uma programação impecável. Quero apenas demonstrar que dá pra fazer &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; direito sem apelação!&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;hr&lt;/span&gt; /&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;form&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;method&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;post&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;action&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;index.php&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      Digite uma nota:&lt;br /&gt;      &lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;text&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;name&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;note&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;name&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;Enviar&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;value&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;Enviar&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;name&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;Enviar&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;value&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;Limpar Notas&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;form&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;hr&lt;/span&gt; /&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h4&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Notas gravadas&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h4&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;hr&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;width&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;40%&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; /&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_leading punctuation_whitespace_embedded_leading_php&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_php&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_php&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;empty&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_global variable_other_global_safer variable_other_global_safer_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;SESSION&lt;/span&gt;&lt;/span&gt;)): &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_trailing punctuation_whitespace_embedded_trailing_php&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_leading punctuation_whitespace_embedded_leading_php&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_php&quot;&gt;foreach&lt;/span&gt; (&lt;span class=&quot;variable variable_other variable_other_global variable_other_global_safer variable_other_global_safer_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;SESSION&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_php&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;note&lt;/span&gt;): &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_trailing punctuation_whitespace_embedded_trailing_php&quot;&gt;&lt;br /&gt;&lt;/span&gt;          &lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_line source_php_embedded_line_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;note&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_leading punctuation_whitespace_embedded_leading_php&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_php&quot;&gt;endforeach&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_trailing punctuation_whitespace_embedded_trailing_php&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_leading punctuation_whitespace_embedded_leading_php&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_php&quot;&gt;endif&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_trailing punctuation_whitespace_embedded_trailing_php&quot;&gt;&lt;br /&gt;&lt;/span&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;hr&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;width&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;40%&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; /&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;small&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;http://dx7lab.com&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Dx7lab&lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;small&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_begin punctuation_definition_tag_begin_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;center&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_end punctuation_definition_tag_end_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_structure meta_tag_structure_any meta_tag_structure_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_structure entity_name_tag_structure_any entity_name_tag_structure_any_html&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_structure meta_tag_structure_any meta_tag_structure_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_structure entity_name_tag_structure_any entity_name_tag_structure_any_html&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Aqui temos um &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;XHTML&lt;/span&gt;&lt;/span&gt; válido que um designer pode entender com muita facilidade. Diríamos pra ele: “Senhor designer, temos aqui um códido &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt; com algum &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; que deixará a página dinâmica. Tudo que estiver entre as tags &amp;lt;? ?&amp;gt; ou &amp;lt;?= ?&amp;gt; é &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;. Qualquer dúvida é só perguntar.”. Por mais incrível que isso possa parecer, um designer consegue entender isso e continuar o seu trabalho naturalmente.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Alguns podem argumentar que mesmo nesse exemplo tem &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; misturado com &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt;. Vamos ser pragmáticos! Não tem nem como comparar os exemplos nesse nível. Antes tinhamos &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; cuspindo tags &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt; com echo e tudo misturado, fazendo uma verdadeira salada. Agora temos &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt; com algumas tags &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; embutidas, assim como teríamos em uma linguagem de templates. Qual a diferença em usar &amp;lt;? if ($a  $b): ?&amp;gt; e { if $a  $b } do Smarty? É basicamente a mesma coisa sem introduzir complexidade com uma nova ferramenta. O problema não é ter &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt; com &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; embutido. O problema é ter &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; cuspindo &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt;! Não temos esse problema no template.tpl. Todas as tags &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; são atômicas: fazem apenas uma coisa e são independentes. Isso é o importante. Em um projeto que precisa usar &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;MVC&lt;/span&gt;&lt;/span&gt;, esse é um bom exemplo de View simples com &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; Puro.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A outra parte seria o &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; propriamente dito.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_html text_html_basic&quot;&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;support support_function support_function_session support_function_session_php&quot;&gt;session_start&lt;/span&gt;()&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_php&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_php&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;empty&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_global variable_other_global_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt;&lt;/span&gt;)) {&lt;br /&gt;  &lt;span class=&quot;variable variable_other variable_other_global variable_other_global_safer variable_other_global_safer_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;SESSION&lt;/span&gt;&lt;/span&gt;[&lt;span class=&quot;support support_function support_function_var support_function_var_php&quot;&gt;var_export&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_global variable_other_global_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt;&lt;/span&gt;[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;note&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;], &amp;#8221;constant constant_language constant_language_php&amp;quot;&amp;gt;true&lt;/span&gt;)] &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_global variable_other_global_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt;&lt;/span&gt;[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;note&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_php&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;variable variable_other variable_other_global variable_other_global_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt;&lt;/span&gt;[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;Enviar&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;] &amp;#8221;keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_php&amp;quot;&amp;gt;==&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;Limpar Notas&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;)&lt;br /&gt;    &amp;#8221;variable variable_other variable_other_global variable_other_global_safer variable_other_global_safer_php&amp;quot;&amp;gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;SESSION&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;meta meta_array meta_array_php&quot;&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_begin punctuation_definition_array_begin_php&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_end punctuation_definition_array_end_php&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_include meta_include_php&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_import keyword_control_import_include keyword_control_import_include_php&quot;&gt;require_once&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;./template.tpl&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&lt;/em&gt;terminator&lt;/em&gt;expression punctuation&lt;/em&gt;terminator&lt;/em&gt;expression&lt;/em&gt;php&amp;quot;&amp;gt;;&lt;/span&gt;&lt;br /&gt;&lt;/em&gt;section punctuation&lt;/em&gt;section&lt;/em&gt;embedded punctuation&lt;/em&gt;section&lt;/em&gt;embedded&lt;/em&gt;end punctuation&lt;/em&gt;section&lt;/em&gt;embedded&lt;/em&gt;end&lt;/em&gt;php&amp;quot;&amp;gt;&lt;/em&gt;php&amp;quot;&amp;gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Temos aqui um &lt;a href=&quot;http://php.net/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; bem simples de fácil entendimento que, no final do arquivo, inclui o template.tpl – nossa View – e faz tudo funcionar de forma organizada.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Não é difícil. O problema é pensar fora da caixa. Como todo mundo aprende assim, programa assim e pronto, sem questionamentos. Pra melhorar criaram ferramentas de templates e quem não usá-las será condenado! Besteira! As ferramentas de templates têm o seu valor e a sua aplicação, todavia não estamos amarrados a elas pra poder escrever código limpo. Isso é o que eu queria mostrar.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-4335268808328080265?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>CakePHP - criando helpers</title>
   <link href="http://rafaeldx7.github.com/2008/10/03/cakephp---criando-helpers.html"/>
   <updated>2008-10-03T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2008/10/03/cakephp---criando-helpers</id>
   <content type="html">&lt;h1&gt;CakePHP &amp;#8211; criando helpers&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;03 Outubro 2008 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;em muitos casos é necessario replicar o mesmo trecho de código nas views de um projeto. assim acaba-se criando uma repetição desnecessária de código. para resolver esse tipo de problema existem os helpers.&lt;br /&gt;&lt;br /&gt;helpers são componentes semelhante a classes que possuem métodos que executam alguma tarefa e devolvem um pedaço de código como resposta. esses métodos podem ser usados nas views de um projeto, evitando a repetição de código. o melhor benefício da centralizaçào de funcionalidades é facilitar a manutenção do código.&lt;br /&gt;&lt;br /&gt;o CakePHP facilita bastante o trabalho fornecendo vários helpers e permitindo que outros sejam criados rapidamente.&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://farm4.static.flickr.com/3192/2776132553_3d0e797855.jpg&quot; /&gt;&lt;br /&gt;&lt;small&gt;&lt;a href=&quot;http://www.flickr.com/photos/slambo_42/2776132553/&quot;&gt;18 tools and a hair&lt;/a&gt;, por &lt;a href=&quot;http://www.flickr.com/photos/slambo_42/&quot;&gt;slambo_42&lt;/a&gt;, sob a&lt;a href=&quot;http://creativecommons.org/licenses/by-sa/2.0/deed.en&quot;&gt;Creative Commons&lt;/a&gt;&lt;/small&gt;&lt;br /&gt;&lt;br /&gt;Criando um Helper&lt;br /&gt;&lt;br /&gt;um helper consiste em apenas um arquivo que fica na pasta /app/views/helpers/. apesar de estar na pasta das views (acho que deveria estar em outro lugar), o código do helper é formado por uma classe &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; que possui métodos que manipulam o que vc quiser e devolvem uma resposta para a view.&lt;br /&gt;&lt;br /&gt;como um exemplo, vamos criar um helper para resolver o seguinte problema: todas as páginas de um site precisam ter um certo banner, que não ficará no topo ou rodapé das páginas, mas em meio ao seu conteúdo. e a imagem desse banner poderá mudar às vezes. &lt;br /&gt;&lt;br /&gt;por mais que seja super simples fazer isso no próprio html, poderemos criar um helper que nos forneça o código desse banner. em todas as páginas que precisarmos dele usaremos o helper. caso haja alteração futura, simplesmente alteraremos o helper.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_block comment_block_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_php&quot;&gt;/&lt;strong&gt;&lt;/span&gt; /app/views/helpers/banner.php &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_php&quot;&gt;&lt;/strong&gt;/&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_class meta_class_php&quot;&gt;&lt;span class=&quot;storage storage_type storage_type_class storage_type_class_php&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_php&quot;&gt;BannerHelper&lt;/span&gt; &lt;span class=&quot;storage storage_modifier storage_modifier_extends storage_modifier_extends_php&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_php&quot;&gt;AppHelper&lt;/span&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_function meta_function_php&quot;&gt;    &lt;span class=&quot;storage storage_type storage_type_function storage_type_function_php&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_php&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_begin punctuation_definition_parameters_begin_php&quot;&gt;(&lt;/span&gt;)&lt;/span&gt; {&lt;br /&gt;        &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;banner&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_double meta_string-contents_quoted_double_php&quot;&gt;&amp;lt;img src=&lt;span class=&quot;constant constant_character constant_character_escape constant_character_escape_php&quot;&gt;\\&amp;quot;&lt;/span&gt;banner.png&lt;span class=&quot;constant constant_character constant_character_escape constant_character_escape_php&quot;&gt;\\&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;        &amp;#8221;keyword keyword_control keyword_control_php&amp;quot;&amp;gt;return&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;this&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_class keyword_operator_class_php&quot;&gt;&amp;#8594;&lt;/span&gt;&lt;span class=&quot;meta meta_function-call meta_function-call_object meta_function-call_object_php&quot;&gt;output&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;banner&lt;/span&gt;)&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;como vc pode ver, criamos um arquivo – /app/views/helpers/banner.php. uma classe que herda de AppHelper – class BannerHelper extends AppHelper. um método simples – show(). dentro desse método retornamos o resultado do método output(), que é responsável por passar os dados que receber para a view.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Usando o novo Helper&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;para usar o novo helper, declare-o no controller:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_class meta_class_php&quot;&gt;&lt;span class=&quot;storage storage_type storage_type_class storage_type_class_php&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_php&quot;&gt;OneController&lt;/span&gt; &lt;span class=&quot;storage storage_modifier storage_modifier_extends storage_modifier_extends_php&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_php&quot;&gt;AppController&lt;/span&gt; {&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;storage storage_type storage_type_php&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;helpers&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;meta meta_array meta_array_php&quot;&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_begin punctuation_definition_array_begin_php&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;BannerHelper&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_end punctuation_definition_array_end_php&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;comment comment_line comment_line_double-slash comment_line_double-slash_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_php&quot;&gt;//&lt;/span&gt; &amp;#8230;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;na view é só chamar:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;banner&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_class keyword_operator_class_php&quot;&gt;&amp;#8594;&lt;/span&gt;&lt;span class=&quot;meta meta_function-call meta_function-call_object meta_function-call_object_php&quot;&gt;show&lt;/span&gt;() &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Aumentando as Possibilidades&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;dentro do helper que vc acabou de criar, é possível usar qualquer outro helper. basta declará-lo, assim como foi feito no controller do exemplo acima.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;vamos incrementar o helper que acabamos de criar. acrescentaremos um link à imagem. pra isso usaremos o HtmlHelper do próprio cake.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_block comment_block_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_php&quot;&gt;/&lt;strong&gt;&lt;/span&gt; /app/views/helpers/banner.php &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_php&quot;&gt;&lt;/strong&gt;/&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_class meta_class_php&quot;&gt;&lt;span class=&quot;storage storage_type storage_type_class storage_type_class_php&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_php&quot;&gt;BannerHelper&lt;/span&gt; &lt;span class=&quot;storage storage_modifier storage_modifier_extends storage_modifier_extends_php&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_php&quot;&gt;AppHelper&lt;/span&gt; {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;storage storage_type storage_type_php&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;helpers&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;meta meta_array meta_array_php&quot;&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_begin punctuation_definition_array_begin_php&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;Html&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_end punctuation_definition_array_end_php&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_function meta_function_php&quot;&gt;    &lt;span class=&quot;storage storage_type storage_type_function storage_type_function_php&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_php&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_begin punctuation_definition_parameters_begin_php&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;meta meta_function meta_function_arguments meta_function_arguments_php&quot;&gt;&lt;span class=&quot;meta meta_function meta_function_argument meta_function_argument_default meta_function_argument_default_php&quot;&gt;&lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;class&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;banner&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;)&lt;/span&gt; {&lt;br /&gt;        &amp;#8221;variable variable_other variable_other_php&amp;quot;&amp;gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;image&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;&lt;img src=&quot;banner.png&quot;&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;url&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;http://dx7lab.com&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;link&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;this&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_class keyword_operator_class_php&quot;&gt;&amp;#8594;&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_property variable_other_property_php&quot;&gt;Html&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_class keyword_operator_class_php&quot;&gt;&amp;#8594;&lt;/span&gt;&lt;span class=&quot;meta meta_function-call meta_function-call_object meta_function-call_object_php&quot;&gt;link&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;image&lt;/span&gt;, &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;url&lt;/span&gt;, &lt;span class=&quot;meta meta_array meta_array_php&quot;&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_begin punctuation_definition_array_begin_php&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;keyword keyword_operator keyword_operator_key keyword_operator_key_php&amp;quot;&amp;gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;class&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_end punctuation_definition_array_end_php&quot;&gt;)&lt;/span&gt;&lt;/span&gt;)&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;banner&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_php&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;&lt;div&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;keyword keyword_operator keyword_operator_string keyword_operator_string_php&amp;quot;&amp;gt;.&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;link&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_string keyword_operator_string_php&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;&lt;/div&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span class=&quot;keyword keyword_control keyword_control_php&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;this&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_class keyword_operator_class_php&quot;&gt;&amp;#8594;&lt;/span&gt;&lt;span class=&quot;meta meta_function-call meta_function-call_object meta_function-call_object_php&quot;&gt;output&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;banner&lt;/span&gt;)&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_expression punctuation_terminator_expression_php&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;agora o banner ficou mais completo com um código simples. temos o caminho da imagem e a url. usamos o HtmlHelper do Cake pra montarmos o link do banner. pra poder usar o HtmlHelper apenas o declaramos logo no início da classe. depois colocamos o banner dentro de uma div. além disso recebemos um parâmetro que será a classe css do link. depois retornamos tudo através do output.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;essa técnica pode ajudar bastante na organização do código do projeto.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-3603259478583168849?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>CakePHP - criando button com o helper</title>
   <link href="http://rafaeldx7.github.com/2008/09/25/cakephp---criando-button-com-o-helper.html"/>
   <updated>2008-09-25T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2008/09/25/cakephp---criando-button-com-o-helper</id>
   <content type="html">&lt;h1&gt;CakePHP &amp;#8211; criando button com o helper&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;25 Setembro 2008 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;caso vc precise dar submit em um formulário usando &lt;button type=&quot;submit&quot;&gt; com um helper do CakePHP, o Form Helper não poderá te ajudar.&lt;br /&gt;&lt;br /&gt;observe os códigos gerados por alguns métodos do form helper que parecem resolver, mas não resolvem, este problema:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_html text_html_basic&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;:&lt;br /&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_class keyword_operator_class_php&quot;&gt;&amp;#8594;&lt;/span&gt;&lt;span class=&quot;meta meta_function-call meta_function-call_object meta_function-call_object_php&quot;&gt;button&lt;/span&gt;(&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;Submit&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;, &amp;#8221;meta meta_array meta_array_php&amp;quot;&amp;gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_begin punctuation_definition_array_begin_php&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;keyword keyword_operator keyword_operator_key keyword_operator_key_php&amp;quot;&amp;gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;submit&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_end punctuation_definition_array_end_php&quot;&gt;)&lt;/span&gt;&lt;/span&gt;) &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_trailing punctuation_whitespace_embedded_trailing_php&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;:&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;value&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;Submit&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;:&lt;br /&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_class keyword_operator_class_php&quot;&gt;&amp;#8594;&lt;/span&gt;&lt;span class=&quot;meta meta_function-call meta_function-call_object meta_function-call_object_php&quot;&gt;submit&lt;/span&gt;(&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;Submit&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;) &amp;#8221;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&amp;quot;&amp;gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_trailing punctuation_whitespace_embedded_trailing_php&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;:&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;value&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;Submit&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;:&lt;br /&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_class keyword_operator_class_php&quot;&gt;&amp;#8594;&lt;/span&gt;&lt;span class=&quot;meta meta_function-call meta_function-call_object meta_function-call_object_php&quot;&gt;end&lt;/span&gt;(&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;Submit&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;) &amp;#8221;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&amp;quot;&amp;gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_trailing punctuation_whitespace_embedded_trailing_php&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;:&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&amp;quot;&amp;gt;value&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;Submit&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;form&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;pra ter o resultado esperado use:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_html text_html_basic&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;:&lt;br /&gt;&lt;span class=&quot;source source_php source_php_embedded source_php_embedded_block source_php_embedded_block_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_begin punctuation_section_embedded_begin_php&quot;&gt;&amp;lt;?=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_php&quot;&gt;$&lt;/span&gt;html&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_class keyword_operator_class_php&quot;&gt;&amp;#8594;&lt;/span&gt;&lt;span class=&quot;meta meta_function-call meta_function-call_object meta_function-call_object_php&quot;&gt;tag&lt;/span&gt;(&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt;, &amp;#8221;meta meta_function-call meta_function-call_php&amp;quot;&amp;gt;&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;Submit&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;constant constant_language constant_language_php&amp;quot;&amp;gt;&lt;/span&gt;, &lt;span class=&quot;meta meta_array meta_array_php&quot;&gt;&lt;span class=&quot;support support_function support_function_construct support_function_construct_php&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_begin punctuation_definition_array_begin_php&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;#8220;&lt;/span&gt;&lt;/span&gt; &amp;#8221;keyword keyword_operator keyword_operator_key keyword_operator_key_php&amp;quot;&amp;gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_php&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;meta meta_string-contents meta_string-contents_quoted meta_string-contents_quoted_single meta_string-contents_quoted_single_php&quot;&gt;submit&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_php&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_array punctuation_definition_array_end punctuation_definition_array_end_php&quot;&gt;)&lt;/span&gt;&lt;/span&gt;) &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_end punctuation_section_embedded_end_php&quot;&gt;&lt;span class=&quot;source source_php&quot;&gt;?&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_whitespace punctuation_whitespace_embedded punctuation_whitespace_embedded_trailing punctuation_whitespace_embedded_trailing_php&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;:&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Submit&lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;muito bem!&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-967521346419333193?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>CakePHP - model sem table</title>
   <link href="http://rafaeldx7.github.com/2008/08/15/cakephp---model-sem-table.html"/>
   <updated>2008-08-15T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2008/08/15/cakephp---model-sem-table</id>
   <content type="html">&lt;h1&gt;CakePHP &amp;#8211; model sem table&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;15 Agosto 2008 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;se vc precisa usar um model sem uma tabela específica do banco de dados, no CakePHP, simplesmente faça:&lt;br /&gt;&lt;br /&gt;class YourModel extends AppModel {&lt;br /&gt;   var $useTable = false;&lt;br /&gt;   // &amp;#8230;&lt;br /&gt;}&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-6268370633145519796?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>CakePHP - controller sem model</title>
   <link href="http://rafaeldx7.github.com/2008/08/15/cakephp---controller-sem-model.html"/>
   <updated>2008-08-15T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2008/08/15/cakephp---controller-sem-model</id>
   <content type="html">&lt;h1&gt;CakePHP &amp;#8211; controller sem model&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;15 Agosto 2008 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;caso vc precise de um controller sem um model específico, no CakePHP, faça: &lt;br /&gt;&lt;br /&gt;class YourController extends AppController { &lt;br /&gt;  var $uses = null;&lt;br /&gt;  &lt;br /&gt;  // também funciona (ou uma coisa ou outra!)&lt;br /&gt;  var $uses = array();&lt;br /&gt;  &lt;br /&gt;  // &amp;#8230;&lt;br /&gt;}&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-4795909154319092393?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>CakePHP - Model::query() no controller ou view</title>
   <link href="http://rafaeldx7.github.com/2008/08/13/cakephp---model--query---no-controller-ou-view.html"/>
   <updated>2008-08-13T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2008/08/13/cakephp---model--query---no-controller-ou-view</id>
   <content type="html">&lt;h1&gt;CakePHP &amp;#8211; Model::query() no controller ou view&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;13 Agosto 2008 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;o método &lt;b&gt;query()&lt;/b&gt; é muito prático por permitir executar qualquer comando &lt;span class=&quot;caps&quot;&gt;SQL&lt;/span&gt; que vc quiser, de onde vc quiser.&lt;br /&gt;&lt;br /&gt;então, vc pode, no controller, fazer assim:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;br /&amp;gt;$this-&amp;gt;MyModel-&amp;gt;query(&quot;SQL statement&quot;);&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;pela convenção do &lt;a href=&quot;http://cakephp.org/&quot;&gt;CakePHP&lt;/a&gt;, este é um jeito válido, pois o método é público. existem vários exemplos na internet utilizando este artifício. mas isso coloca no controller uma chamada ao banco de dados, o que viola o padrão &lt;a href=&quot;http://pt.wikipedia.org/wiki/Model-view-controller&quot;&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;MVC&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;. e espero que vc &lt;b&gt;nunca nem pense&lt;/b&gt; em colocar tal coisa na view.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;essa é uma maneira “errada”, não limpa e pode zonear todo o seu projeto.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;prefira colocar as consultas ao banco no seu Model, desta forma:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;br /&amp;gt;/* no model */&amp;lt;br /&amp;gt;public function doSomething() {&amp;lt;br /&amp;gt;return $this-&amp;gt;query(&quot;SQL statement&quot;);&amp;lt;br /&amp;gt;}&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;br /&amp;gt;/* no controller */&amp;lt;br /&amp;gt;$this-&amp;gt;MyModel-&amp;gt;doSomething();&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;assim seu código fica mais limpo, organizado, com uma leitura mais fácil e esta consulta pode ser utilizada em outras actions ou controllers.&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-7836712700060597894?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>CakePHP - link em imagens com o html helper</title>
   <link href="http://rafaeldx7.github.com/2008/08/08/cakephp---link-em-imagens-com-o-html-helper.html"/>
   <updated>2008-08-08T00:00:00-03:00</updated>
   <id>http://rafaeldx7.github.com/2008/08/08/cakephp---link-em-imagens-com-o-html-helper</id>
   <content type="html">&lt;h1&gt;CakePHP &amp;#8211; link em imagens com o html helper&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;08 Agosto 2008 &amp;#8211; Niterói/RJ&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.essentialsystems.co.uk/blog/wp-content/uploads/2008/04/cakephp.gif&quot; /&gt;&lt;br /&gt;&lt;br /&gt;estou desenvolvendo um projeto utilizando o &lt;a href=&quot;http://cakephp.org/&quot;&gt;CakePHP&lt;/a&gt;. estou gostando bastante. não é nenhum Rails, mas é um grande passo no mundo &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;com isso, devo postar algumas dicas aqui baseadas na minha experiência do dia a dia. talvez consiga ajudar mais pessoas que também estejam começando com o &lt;a href=&quot;http://cakephp.org/&quot;&gt;CakePHP&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;a primeira dica é como colocar um link em uma imagem com o html helper. parece besteira, mas tem um detalhe que me fez perder alguns bons minutos.&lt;br /&gt;&lt;br /&gt;pra colocar um link a gente sempre utiliza, em uma view, algo parecido com:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;br /&amp;gt;&amp;lt;?= $html-&amp;gt;link(&quot;clique aqui&quot;, array(&quot;action&quot;=&amp;gt;&quot;view&quot;, $id)) ?&amp;gt;&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;pra colocar uma imagem:&lt;br /&gt;&lt;code&gt;&amp;lt;br /&amp;gt;&amp;lt;?= $html-&amp;gt;image(&quot;img/foto.jpg&quot;) ?&amp;gt;&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;logo, concluímos que pra colocar uma imagem com um link, temos que fazer:&lt;br /&gt;&lt;code&gt;&amp;lt;br /&amp;gt;&amp;lt;?= $html-&amp;gt;link($html-&amp;gt;image(&quot;img/foto.jpg&quot;), array(&quot;action&quot;=&amp;gt;&quot;view&quot;, $id)) ?&amp;gt;&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;só que falta um detalhe muito importante. se vc fizer exatamente como o código acima, verá a tag img na tela. isso porque o helper “espapa” o código dela. pra funcionar, vc precisa passar mais algums parâmetros e deixar assim:&lt;br /&gt;&lt;code&gt;&amp;lt;br /&amp;gt;&amp;lt;?= $html-&amp;gt;link($html-&amp;gt;image(&quot;img/foto.jpg&quot;), array(&quot;action&quot;=&amp;gt;&quot;view&quot;, $id), null, false, false) ?&amp;gt;&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;dessa forma vc terá a sua imagem com um link e seus problemas estarão resolvidos!&lt;br /&gt;&lt;br /&gt;para mais detalhes: &lt;a href=&quot;http://api.cakephp.org/class_html_helper.html&quot;&gt;CakePHP HtmlHelper Class Reference&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1372066769163881306-1932909615059730685?l=rafael.xlii.com.br' alt='' /&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 
</feed>