<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CakePHP Brasil &#187; jquery</title>
	<atom:link href="http://blog.cakephp-brasil.org/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cakephp-brasil.org</link>
	<description>O blog público para desenvolvedores CakePHP.</description>
	<lastBuildDate>Thu, 29 Jul 2010 01:05:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Trabalhando com JSON no CakePHP 1.2</title>
		<link>http://blog.cakephp-brasil.org/2008/09/11/trabalhando-com-json-no-cakephp-12/</link>
		<comments>http://blog.cakephp-brasil.org/2008/09/11/trabalhando-com-json-no-cakephp-12/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 01:13:44 +0000</pubDate>
		<dc:creator>Juan Basso</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Tutoriais]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://blog.cakephp-brasil.org/?p=52</guid>
		<description><![CDATA[Com o crescimento do uso de AJAX, da maioria dos frameworks de JavaScript (jQuery, Prototype, mooTools, YUI, ExtJS, &#8230;) e de uma dúvida no Groups do Google (Action que renderize apenas o layout, sem necessidade de uma view), resolvi escrever um post falando sobre como usar JSON no CakePHP de forma automática para retorno dos [...]]]></description>
			<content:encoded><![CDATA[<p>Com o crescimento do uso de AJAX, da maioria dos frameworks de JavaScript (jQuery, Prototype, mooTools, YUI, ExtJS, &#8230;) e de uma dúvida no Groups do Google (<a href="http://groups.google.com/group/cake-php-pt/browse_thread/thread/5052c43d26bfb477" target="_blank">Action que renderize apenas o layout, sem necessidade de uma view</a>), resolvi escrever um post falando sobre como usar JSON no CakePHP de forma automática para retorno dos dados, sem precisar gerar um arquivo de view para cada action e que não fere o MVC.<br />
<span style="font-weight: bold;">A Solução</span></p>
<p>Para solucionar o caso, achei que o melhor jeito seria criando uma classe de View nova. A classe View do CakePHP ela sempre procura um arquivo de view, além do template. Com a nova classe, seria feita a renderização ali mesmo, sem a necessidade de novos arquivos.</p>
<p>A classe que criei (JsonView) pode ser baixada <a href="http://blog.cakephp-brasil.org/wp-content/uploads/2008/09/json1.phps">aqui</a>. Ela deve ser colocada na pasta <span style="font-weight: bold;">views</span> de da sua aplicação (nenhuma sub-pasta) com o nome de <span style="font-weight: bold;">json.php</span>. Ou seja, no final, você terá o caminho <span style="font-weight: bold;">app/views/json.php</span>.<br />
<span style="font-weight: bold;">Como Usar</span></p>
<p>Para usar é bem simples. No seu controller, quando você for retornar um código em JSON, basta alterar a variável $view do controller para usar a nova classe. Além disso, os dados que você quer que retorne, devem ser setados com o nome &#8216;<span style="font-weight: bold;">json</span>&#8216; no seu controller. Caso não seja, ele vai renderizar normalmente. Exemplo de uso no controller:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p52code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p522"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code" id="p52code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> UsuariosController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$uses</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Usuario'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Grupo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #000088;">$json</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'usuarios'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Usuario</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'list'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$json</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Json'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'json'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'usuarios'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> multilista<span style="color: #009900;">&#40;</span><span style="color: #000088;">$json</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'usuarios'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Usuario</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'list'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'grupos'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Grupo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'list'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$json</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Json'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'json'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'usuarios'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'grupos'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Neste caso, quando o parâmetro de <span style="font-weight: bold;">index</span> não for true, ele vai renderizar como se fosse uma requisição normal. Caso passe como true, ele irá renderizar como JSON. Já no método <span style="font-weight: bold;">multilista</span>, além do parâmetro para verificar se é JSON, ele passa um array de variáveis para a view JSON, assim a classe irá renderizar mais de uma variável.</p>
<p>Outra maneira de se fazer é definir a variável $view da classe diretamente com &#8216;Json&#8217; (assim como foi feito com $uses no exemplo). Assim, sempre que você der um set na variável &#8216;json&#8217;, a classe da View se liga e renderiza em json, caso contrário mantém o normal.</p>
<p><span style="font-weight: bold;">Conclusão</span></p>
<p>Este é um método fácil e rápido de renderizar as requisições JSON, sem precisar criar um arquivo para cada requisição e sem precisar de muito código (tanto no controller, quanto na view).</p>
<p>O código que fiz, é compatível com PHP 4 e 5, então é possível usar com o CakePHP sem medo em qualquer versão de PHP.</p>
<p>Abraços e bom uso. <img src='http://blog.cakephp-brasil.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Dicas são sempre bem vindas.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cakephp-brasil.org/2008/09/11/trabalhando-com-json-no-cakephp-12/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Usando FlexiGrid com CakePHP</title>
		<link>http://blog.cakephp-brasil.org/2008/07/30/usando-flexigrid-com-cakephp/</link>
		<comments>http://blog.cakephp-brasil.org/2008/07/30/usando-flexigrid-com-cakephp/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 03:05:14 +0000</pubDate>
		<dc:creator>Juan Basso</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Tutoriais]]></category>
		<category><![CDATA[ext]]></category>
		<category><![CDATA[flexigrid]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[lista]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[tabela]]></category>

		<guid isPermaLink="false">http://blog.cakephp-brasil.org/?p=32</guid>
		<description><![CDATA[Pessoal,
Depois de escrever sobre como usar o TableSorter com CakePHP, vou escrever agora sobre o FlexiGrid. Mostrar como implementar o exemplo mais sofisticado que eles apresentam no site deles.
Primeiramente, vamos baixar os arquivos necessários:
jQuery: http://jquery.com (mais recente no momento é a 1.2.6)
FlexiGrid: http://www.webplicity.net/flexigrid/ (estou me baseando na versão 1.0b3)
Colocar os arquivos (jquery.js e flexigrid.js) na [...]]]></description>
			<content:encoded><![CDATA[<p>Pessoal,</p>
<p>Depois de escrever sobre <a href="http://blog.cakephp-brasil.org/2008/07/28/usando-o-tablesorter-com-cakephp/">como usar o TableSorter com CakePHP</a>, vou escrever agora sobre o FlexiGrid. Mostrar como implementar o exemplo mais sofisticado que eles apresentam no site deles.</p>
<p>Primeiramente, vamos baixar os arquivos necessários:</p>
<li>jQuery: <a href="http://jquery.com">http://jquery.com</a> (mais recente no momento é a 1.2.6)</li>
<li>FlexiGrid: <a href="http://www.webplicity.net/flexigrid/">http://www.webplicity.net/flexigrid/</a> (estou me baseando na versão 1.0b3)</li>
<p>Colocar os arquivos (jquery.js e flexigrid.js) na pasta vendors\js ou webroot\js, conforme sua preferência.</p>
<p><strong>Agora na view que vai mostrar a tabela:</strong></p>
<p>Carregar os javascripts:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p32code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p327"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p32code7"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$javascript</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'flexigrid'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Feito isso, incluir o seguinte código na página para exibir a tabela (PS: esse código eu copiei exatamente como está na página do Flexigrid):</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p32code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p328"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
</pre></td><td class="code" id="p32code8"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>style<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">.</span>flexigrid div<span style="color: #339933;">.</span>fbutton <span style="color: #339933;">.</span>add <span style="color: #009900;">&#123;</span>
		background<span style="color: #339933;">:</span> url<span style="color: #009900;">&#40;</span>css<span style="color: #339933;">/</span>images<span style="color: #339933;">/</span>add<span style="color: #339933;">.</span>png<span style="color: #009900;">&#41;</span> no<span style="color: #339933;">-</span>repeat center left<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
&nbsp;
	<span style="color: #339933;">.</span>flexigrid div<span style="color: #339933;">.</span>fbutton <span style="color: #339933;">.</span>delete <span style="color: #009900;">&#123;</span>
		background<span style="color: #339933;">:</span> url<span style="color: #009900;">&#40;</span>css<span style="color: #339933;">/</span>images<span style="color: #339933;">/</span>close<span style="color: #339933;">.</span>png<span style="color: #009900;">&#41;</span> no<span style="color: #339933;">-</span>repeat center left<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #339933;">&lt;/</span>style<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>table id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;flex1&quot;</span> style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;display:none&quot;</span><span style="color: #339933;">&gt;&lt;/</span>table<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#flex1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>flexigrid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		url<span style="color: #339933;">:</span> <span style="color: #0000ff;">'&lt;?php echo Router::url(array('</span>controller<span style="color: #0000ff;">' =&gt; '</span>flexi<span style="color: #0000ff;">', '</span>action<span style="color: #0000ff;">' =&gt; '</span>index<span style="color: #0000ff;">'), true); ?&gt;'</span><span style="color: #339933;">,</span>
		dataType<span style="color: #339933;">:</span> <span style="color: #0000ff;">'json'</span><span style="color: #339933;">,</span>
		colModel <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
			<span style="color: #009900;">&#123;</span>display<span style="color: #339933;">:</span> <span style="color: #0000ff;">'ISO'</span><span style="color: #339933;">,</span> name <span style="color: #339933;">:</span> <span style="color: #0000ff;">'iso'</span><span style="color: #339933;">,</span> width <span style="color: #339933;">:</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span> sortable <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> align<span style="color: #339933;">:</span> <span style="color: #0000ff;">'center'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
			<span style="color: #009900;">&#123;</span>display<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Name'</span><span style="color: #339933;">,</span> name <span style="color: #339933;">:</span> <span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> width <span style="color: #339933;">:</span> <span style="color: #cc66cc;">180</span><span style="color: #339933;">,</span> sortable <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> align<span style="color: #339933;">:</span> <span style="color: #0000ff;">'left'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
			<span style="color: #009900;">&#123;</span>display<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Printable Name'</span><span style="color: #339933;">,</span> name <span style="color: #339933;">:</span> <span style="color: #0000ff;">'printable_name'</span><span style="color: #339933;">,</span> width <span style="color: #339933;">:</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> sortable <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> align<span style="color: #339933;">:</span> <span style="color: #0000ff;">'left'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
			<span style="color: #009900;">&#123;</span>display<span style="color: #339933;">:</span> <span style="color: #0000ff;">'ISO3'</span><span style="color: #339933;">,</span> name <span style="color: #339933;">:</span> <span style="color: #0000ff;">'iso3'</span><span style="color: #339933;">,</span> width <span style="color: #339933;">:</span> <span style="color: #cc66cc;">130</span><span style="color: #339933;">,</span> sortable <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> align<span style="color: #339933;">:</span> <span style="color: #0000ff;">'left'</span><span style="color: #339933;">,</span> hide<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
			<span style="color: #009900;">&#123;</span>display<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Number Code'</span><span style="color: #339933;">,</span> name <span style="color: #339933;">:</span> <span style="color: #0000ff;">'numcode'</span><span style="color: #339933;">,</span> width <span style="color: #339933;">:</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> sortable <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> align<span style="color: #339933;">:</span> <span style="color: #0000ff;">'right'</span><span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
		buttons <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
			<span style="color: #009900;">&#123;</span>name<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Add'</span><span style="color: #339933;">,</span> bclass<span style="color: #339933;">:</span> <span style="color: #0000ff;">'add'</span><span style="color: #339933;">,</span> onpress <span style="color: #339933;">:</span> test<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
			<span style="color: #009900;">&#123;</span>name<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Delete'</span><span style="color: #339933;">,</span> bclass<span style="color: #339933;">:</span> <span style="color: #0000ff;">'delete'</span><span style="color: #339933;">,</span> onpress <span style="color: #339933;">:</span> test<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
			<span style="color: #009900;">&#123;</span>separator<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
		searchitems <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
			<span style="color: #009900;">&#123;</span>display<span style="color: #339933;">:</span> <span style="color: #0000ff;">'ISO'</span><span style="color: #339933;">,</span> name <span style="color: #339933;">:</span> <span style="color: #0000ff;">'iso'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
			<span style="color: #009900;">&#123;</span>display<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Name'</span><span style="color: #339933;">,</span> name <span style="color: #339933;">:</span> <span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> isdefault<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
		sortname<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;iso&quot;</span><span style="color: #339933;">,</span>
		sortorder<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;asc&quot;</span><span style="color: #339933;">,</span>
		usepager<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		title<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Paises'</span><span style="color: #339933;">,</span>
		useRp<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		rp<span style="color: #339933;">:</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span>
		showTableToggleBtn<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">700</span><span style="color: #339933;">,</span>
		height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span>
		pagestat<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Mostrando {from} até {to} de {total} itens'</span><span style="color: #339933;">,</span>
		procmsg<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Processando, aguarde...'</span><span style="color: #339933;">,</span>
		nomsg<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Nenhum item'</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> test<span style="color: #009900;">&#40;</span>com<span style="color: #339933;">,</span>grid<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>com <span style="color: #339933;">==</span> <span style="color: #0000ff;">'Delete'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			confirm<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Excluir '</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.trSelected'</span><span style="color: #339933;">,</span>grid<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>length <span style="color: #339933;">+</span> <span style="color: #0000ff;">' itens?'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>com <span style="color: #339933;">==</span> <span style="color: #0000ff;">'Add'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Adicionar novo item'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></pre></td></tr></table></div>

<p>Pronto, nossa view está pronta para exibir os dados. <strong>Agora vamos para a parte dos dados:</strong></p>
<p>Vamos começar pelo controller (controllers/flexi_controller.php):</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p32code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p329"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code" id="p32code9"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> FlexiController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Flexi'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$uses</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Configure<span style="color: #339933;">::</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'debug'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'form'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'limit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$rp</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$page</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
				<span style="color: #000088;">$sortname</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$sortorder</span>
			<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginate</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conditions'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$qtype</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' LIKE'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'%'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$query</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'%'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: text/x-json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'paises'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ajax'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Duas considerações: desativar o debug é para que ele não exiba erros/warnings de PHP e o tempo de carregamento no final. O layout ajax é para ele não incluir nada a mais que o que eu colocar na view.</p>
<p>Bem, feito isso no controller, vamos para a view (views/flexi/index.ctp), montar nosso JSON na mão&#8230; <img src='http://blog.cakephp-brasil.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p32code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3210"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p32code10"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$paginator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #009900;">&#123;</span> page<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">,</span> total<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">,</span> rows<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$registros</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$paises</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$pais</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$registros</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;{id: '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pais</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'iso'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;', cell: ['&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pais</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'iso'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;', '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pais</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;', '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pais</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'printable_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;', '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pais</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'iso3'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;', '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pais</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'numcode'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;']}&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$registros</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Pronto, isso aí vai gerar o JSON necessário para o Flexigrid. Já dá para brincar com ordenação, troca de páginas, filtro&#8230;</p>
<p>Qualquer coisa, só comentar!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cakephp-brasil.org/2008/07/30/usando-flexigrid-com-cakephp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Usando o TableSorter com CakePHP</title>
		<link>http://blog.cakephp-brasil.org/2008/07/28/usando-o-tablesorter-com-cakephp/</link>
		<comments>http://blog.cakephp-brasil.org/2008/07/28/usando-o-tablesorter-com-cakephp/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 00:26:40 +0000</pubDate>
		<dc:creator>Juan Basso</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Tutoriais]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[ordernar]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sorter]]></category>
		<category><![CDATA[tabela]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[tablesorter]]></category>
		<category><![CDATA[vendor]]></category>

		<guid isPermaLink="false">http://blog.cakephp-brasil.org/?p=28</guid>
		<description><![CDATA[Pessoal, depois de um tempo sumido devido a alguns trabalhos que me consumiram muito tempo, estou voltando&#8230;
Hoje vou falar de uma experiência que tive com o TableSorter com CakePHP na construção de uma página, não me atendo muito a detalhes de design, mas da parte funcional. No grupos de CakePHP PT eu tinha falado que [...]]]></description>
			<content:encoded><![CDATA[<p>Pessoal, depois de um tempo sumido devido a alguns trabalhos que me consumiram muito tempo, estou voltando&#8230;</p>
<p>Hoje vou falar de uma experiência que tive com o TableSorter com CakePHP na construção de uma página, não me atendo muito a detalhes de design, mas da parte funcional. No grupos de CakePHP PT eu tinha falado que ia fazer, mas fazem quase dois meses e nada, porém agora lá vai&#8230; Bill: desculpe a demora. <img src='http://blog.cakephp-brasil.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Primeiro, baixem o jQuery (<a href="http://jquery.com">http://jquery.com</a>) e o plugin TableSorter (<a href="http://tablesorter.com">http://tablesorter.com</a>).</p>
<p>Extraia os arquivos baixados (jquery.js e jquery.tablesorter.js) em alguma vendors\js ou webroot\js. Eu particularmente prefiro deixar na pasta vendors, pois são plugins de terceiros ou que não são exclusivos da aplicação. Em contra partida, deixar na pasta webroot polpa o trabalho do servidor executar o cake para procurar, reduzindo o tempo de resposta. Aí vai do gosto de cada um. Eu prefiro perder tempo para deixar as coisas nos seus devidos lugares&#8230;</p>
<p>No controller, você precisa apenas declarar que vai usar o helper Javascript:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p28code15'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2815"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p28code15"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$helpers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">...,</span> <span style="color: #0000ff;">'Javascript'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Feito isso, criamos uma tabela na view do que queremos mostar:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p28code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2816"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code" id="p28code16"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>table border<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;detalhe_compra&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>caption<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Detalhe por compra'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>caption<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>thead<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pedido'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Data'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cliente'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Valor'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>thead<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>tfoot<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td colspan<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #339933;">&gt;&amp;</span>nbsp<span style="color: #339933;">;&lt;/</span>td<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$number</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currency</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$totalPedidos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>tfoot<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>tbody<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pedidos</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$pedido</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$pedido</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Pedido'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'numero'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$pedido</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Pedido'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$pedido</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Cliente'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nome'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$pedido</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Pedido'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'valor'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #339933;">&lt;/</span>tbody<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Depois, ainda na mesma view, basta colocar o seguinte código para carregar os arquivos de javascript no head:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p28code17'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2817"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p28code17"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$javascript</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'jquery.tablesorter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Em seguida, configurar o TableSorter para agir sobre a tabela:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p28code18'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2818"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p28code18"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$javascript</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">codeBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	$(document).ready(function(){
		$(&quot;#detalhe_compra&quot;).tablesorter({decimal: &quot;,&quot;, dateFormat: &quot;uk&quot;});
	});'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'inline'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Nas configurações da tabela, defini que os números possuem o vírgula como separador decimal e a data no formato inglês (similar ao nosso).</p>
<p>Pronto, só isso já faz funcionar o TableSorter. Outras configurações, podem olhar no site do TableSorter e ver. Lá é bem documentado e tranquilo.</p>
<p>Abraços e boa sorte a todos, qualquer coisa, é só comentar.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cakephp-brasil.org/2008/07/28/usando-o-tablesorter-com-cakephp/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Usando jQuery com CakePHP</title>
		<link>http://blog.cakephp-brasil.org/2008/05/19/usando-jquery-com-cakephp/</link>
		<comments>http://blog.cakephp-brasil.org/2008/05/19/usando-jquery-com-cakephp/#comments</comments>
		<pubDate>Mon, 19 May 2008 23:59:03 +0000</pubDate>
		<dc:creator>Juan Basso</dc:creator>
				<category><![CDATA[Tutoriais]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://blog.cakephp-brasil.org/?p=13</guid>
		<description><![CDATA[Vendo o questionamento de muitas pessoas no Google Groups, vou explicar como usar o jQuery juntamente com o CakePHP.
A primeira coisa que você tem que fazer é baixar o código do jQuery e colocá-lo na pasta vendors\js (tanto faz ser na vendors dentro de app ou fora). Depois disso, nos controllers que você for utilizar o [...]]]></description>
			<content:encoded><![CDATA[<p>Vendo o questionamento de muitas pessoas no <a title="Google Groups" href="http://groups.google.com/group/cake-php-pt" target="_blank">Google Groups</a>, vou explicar como usar o <a title="jQuery" href="http://jquery.com" target="_blank">jQuery</a> juntamente com o CakePHP.</p>
<p>A primeira coisa que você tem que fazer é baixar o código do jQuery e colocá-lo na pasta vendors\js (tanto faz ser na vendors dentro de app ou fora). Depois disso, nos controllers que você for utilizar o jQuery, inclua o helper Javascript:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p13code21'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1321"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p13code21"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> SeuController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$helpers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Javascript'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Se você usa em todas as páginas, pode colocar isto no seu AppController.</p>
<p>Feito isso, você pode usar na sua view (ou layout) o seguinte código:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p13code22'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1322"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p13code22"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Incluir o jQuery ao projeto</span>
<span style="color: #666666; font-style: italic;">// Neste exemplo estou importando a jquery.tablesorter também</span>
<span style="color: #666666; font-style: italic;">// O segundo parâmetro (false) é para indicar que vai no &lt;head&gt; e não no local onde está sendo executado</span>
<span style="color: #000088;">$javascript</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'jquery.tablesorter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Aqui vou definir alguns comandos de jQuery</span>
<span style="color: #000088;">$javascript</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">codeBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
  $(document).ready(function(){
    $(&quot;#detalhe_compra&quot;).tablesorter({decimal: &quot;,&quot;, dateFormat: &quot;uk&quot;});
    $(&quot;#resumo_compras&quot;).tablesorter({decimal: &quot;,&quot;, dateFormat: &quot;uk&quot;});
  });'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'inline'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
Minha view normalmente<span style="color: #339933;">...</span></pre></td></tr></table></div>

<p>Com isso, você faz que o código javascript vá para o &lt;head&gt; do seu HTML e não fique no meio das suas views, o que é deselegante e fora do padrão W3C.</p>
<p>Num próximo post explico como usar jQuery e AJAX.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cakephp-brasil.org/2008/05/19/usando-jquery-com-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
