<?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>cleiver.com &#187; CakePHP</title>
	<atom:link href="http://blog.cleiver.com/tag/cake/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cleiver.com</link>
	<description>blog</description>
	<lastBuildDate>Wed, 18 Nov 2009 00:37:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Updates</title>
		<link>http://blog.cleiver.com/2009/09/17/updates/</link>
		<comments>http://blog.cleiver.com/2009/09/17/updates/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 01:57:25 +0000</pubDate>
		<dc:creator>Cleiver</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Devaneios]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[desenvolvimento]]></category>
		<category><![CDATA[how u' doing?]]></category>
		<category><![CDATA[inea]]></category>
		<category><![CDATA[Livros]]></category>
		<category><![CDATA[nada]]></category>
		<category><![CDATA[viajei]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://blog.cleiver.com/?p=270</guid>
		<description><![CDATA[3 meses se passaram e poucas coisas aconteceram. Sofri um interesse repentino pelo mundo econÃ´mico, li vÃ¡rios livros, assinei o feed de alguns sites, to ouvindo um podcast eÂ voltei a investir na bolsa. Enfim&#8230;
No trabalho as coisas finalmente ficaram interessantes de umas semanas pra cÃ¡. Me tornei o responsÃ¡vel pelo novo sistema de controle de [...]]]></description>
			<content:encoded><![CDATA[<p>3 meses se passaram e poucas coisas aconteceram. Sofri um interesse repentino pelo mundo econÃ´mico, li <a title="Alguns livros que li :P" href="http://www.livrariasaraiva.com.br/pesquisaweb/pesquisaweb.dll/pesquisa?ESTRUTN1=030101&amp;ESTRUTN2=03010104&amp;ORDEMN2=E" target="_blank">vÃ¡rios livros</a>, assinei o feed de alguns sites, to ouvindo um <a title="Podcast dinheirama.com" href="http://dinheirama.com/blog/category/podcast-dinheirama/" target="_blank">podcast</a> eÂ voltei a <a title="GeraÃ§Ã£o futuro" href="http://www.gerafuturo.com.br" target="_blank">investir na bolsa</a>. Enfim&#8230;</p>
<p>No trabalho as coisas finalmente ficaram interessantes de umas semanas pra cÃ¡. Me tornei o responsÃ¡vel pelo novo sistema de controle de agrotÃ³xicos do <a title="Estado do Rio de Janeiro" href="http://www.governo.rj.gov.br/" target="_blank">Estado</a>. FaÃ§o parte da comissÃ£o responsÃ¡vel pela migraÃ§Ã£o do novo site do <a title="INEA - Instituto Estadual do Ambiente" href="http://www.inea.rj.gov.br" target="_blank">Instituto</a> e sou o responsÃ¡vel &#8220;suplente&#8221; nos sistemas de controle da Ã¡gua e do ar. NÃ£o que isso signifique alguma coisa, mas jÃ¡ acumulei mais horas em reuniÃµes nos Ãºltimos dois meses do que em todos os outros trabalhos anteriores. :P</p>
<p>Tenho sentido falta de programar. O mimimi da vez Ã© que quando tenho tempo, falta disposiÃ§Ã£o. Quando tenho disposiÃ§Ã£o, falta tempo. :/ Mas hoje consegui juntar ambos e dei uma brincada. Baixei o novo <a title="Zend Studio 7.0.1" href="http://www.zend.com/en/products/studio/" target="_blank">Zend Studio</a> e aproveitei para dar mais uma testada na <a title="Zend Framework" href="http://framework.zend.com/" target="_blank">Zend Framework</a>. E definitivamente, nÃ£o rola. Ã´ bagulho totalmente desnecessariamente complexo. Ainda mais quando se conhece o <a title="CakePHP Framework" href="http://cakephp.org/" target="_blank">CakePHP</a>.</p>
<p>O pior, pra mim, Ã© que no tal &#8220;<a title="Zend Framework Quick Start" href="http://framework.zend.com/docs/quickstart" target="_blank">guia rÃ¡pido</a> em 30 minutos&#8221; do site oficial, estÃ¡ escrito o seguinte:</p>
<blockquote><p>While Zend Framework is itself configurationless, you often need to configure your application.</p></blockquote>
<p>Com isso eu entendo que a framework deveria ser <em>plug-n-play</em> e eu sÃ³ configuraria coisas que nÃ£o sÃ£o padrÃ£o ou que eu mesmo quisesse diferente (<a title="CakePHP Framework" href="http://cakephp.org/" target="_blank">CakePHP</a>? Oi?). No entanto, 30 minutos eu perdi somente configurando o bÃ¡sico da framework, isso enquanto seguia o prÃ³prio tutorial, e nÃ£o sozinho, no chute. E olha que o Zend Studio cria toda a estrutura bÃ¡sica e arquivos de configuraÃ§Ã£o e controllers bÃ¡sicos. Sem falar na burocracia orientada a objetos para se criar uma simples conexÃ£o com o banco de dados (que nÃ£o funcionou, diga-se).</p>
<p>Enfim, <a title="CakePHP Framework" href="http://cakephp.org/">CakePHP</a> it is. Vou voltar a fazer umas paradas, brincar com o <a title="SimpleTest" href="http://www.simpletest.org/" target="_blank">SimpleTest</a>, HTML5, CSS3, tentar ser mais ativo no grupo <a title="PHP Rio" href="http://www.phprio.org/" target="_blank">PHP Rio</a>&#8230; vamos ver no que dÃ¡! :D</p>


<p>Nenhum post relacionado.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.cleiver.com/2009/09/17/updates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CakePHP e o Auth Component</title>
		<link>http://blog.cleiver.com/2009/03/31/cakephp-e-o-auth-component/</link>
		<comments>http://blog.cleiver.com/2009/03/31/cakephp-e-o-auth-component/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 20:06:34 +0000</pubDate>
		<dc:creator>Cleiver</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[dicas]]></category>

		<guid isPermaLink="false">http://blog.cleiver.com/?p=201</guid>
		<description><![CDATA[O Auth deve ser o componente mais conhecido do CakePHP. Sua funÃ§Ã£o Ã© bem simples: Autenticar um usuÃ¡rio no sistema e gerenciar quais pÃ¡ginas sÃ£o de acesso restrito.
HÃ¡ umas semanas atrÃ¡s eu estava configurando a framework pra um projeto que vou fazer com a Bruna e tive alguns problemas com esse componente. Ele faz muito [...]]]></description>
			<content:encoded><![CDATA[<p>O <a title="Manual do Auth Component" href="http://book.cakephp.org/view/172/Authentication" target="_blank">Auth</a> deve ser o componente mais conhecido do <a title="CakePHP Framework" href="http://cakephp.org/" target="_blank">CakePHP</a>. Sua funÃ§Ã£o Ã© bem simples: Autenticar um usuÃ¡rio no sistema e gerenciar quais pÃ¡ginas sÃ£o de acesso restrito.</p>
<p>HÃ¡ umas semanas atrÃ¡s eu estava configurando a framework pra um projeto que vou fazer com a <a title="Blog da Bruna" href="http://www.brunamorato.com/blog" target="_blank">Bruna</a> e tive alguns problemas com esse componente. Ele faz muito mais do que eu preciso e de uma forma que nÃ£o me agrada muito: nÃ£o me deixando no controle do que acontece.</p>
<p>EntÃ£o comecei a desenvolver um componente pra fazer exatamente que eu quero, ou seja, definir quais pÃ¡ginas serÃ£o acessÃ­veis por usuÃ¡rios deslogados. E sÃ³.</p>
<p>Com 110 linhas de cÃ³digos, incluindo linhas em branco e comentÃ¡rios inÃºteis, ele estÃ¡ funcionando e me atendendo atÃ© agora. Vou dar mais um tempo, usar mais um pouco, ver se nÃ£o to esquecendo de nada, quando estiver mais maduro, disponibilizo aqui.</p>


<p>Nenhum post relacionado.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.cleiver.com/2009/03/31/cakephp-e-o-auth-component/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Inflection em PortuguÃªs do Brasil para o CakePHP</title>
		<link>http://blog.cleiver.com/2009/03/27/inflection-em-portugues-do-brasil-para-o-cakephp/</link>
		<comments>http://blog.cleiver.com/2009/03/27/inflection-em-portugues-do-brasil-para-o-cakephp/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 20:45:02 +0000</pubDate>
		<dc:creator>Cleiver</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[dicas]]></category>

		<guid isPermaLink="false">http://blog.cleiver.com/?p=203</guid>
		<description><![CDATA[Resumidamente, no CakePHP, inflections sÃ£o as regras para pluralizaÃ§Ã£o utilizada pela framework, de modo que ele consiga ir do model para o controller sem problemas segundo suas convenÃ§Ãµes.
Como tenho preguiÃ§a de fazer coisas que certamente jÃ¡ foram feitas e atÃ© melhor que eu faria, resolvi procurar o arquivo pronto. E encontrei na pasta do Gabriel [...]]]></description>
			<content:encoded><![CDATA[<p>Resumidamente, no <a title="CakePHP" href="http://cakephp.org" target="_blank">CakePHP</a>, inflections sÃ£o as regras para pluralizaÃ§Ã£o utilizada pela framework, de modo que ele consiga ir do model para o controller sem problemas segundo suas convenÃ§Ãµes.</p>
<p>Como tenho preguiÃ§a de fazer coisas que certamente jÃ¡ foram feitas e atÃ© melhor que eu faria, resolvi procurar o arquivo pronto. E encontrei na <a href="http://github.com/gabrielgilini/cake_ptbr/blob/master/config/inflections.php" target="_blank">pasta do Gabriel</a> no <a title="Github!" href="http://github.com" target="_blank">Github</a>. NÃ£o sei qual a frequencia de atualizaÃ§Ã£o nem se contem muitos erros, mas se tiver algum, atualizar Ã© moleza, basta olhar o arquivo que dÃ¡ pra entender a lÃ³gica.</p>


<p>Nenhum post relacionado.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.cleiver.com/2009/03/27/inflection-em-portugues-do-brasil-para-o-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Micro projeto em CakePHP</title>
		<link>http://blog.cleiver.com/2008/11/12/micro-projeto-em-cakephp/</link>
		<comments>http://blog.cleiver.com/2008/11/12/micro-projeto-em-cakephp/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 18:52:39 +0000</pubDate>
		<dc:creator>Cleiver</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Projetos]]></category>
		<category><![CDATA[nada]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.cleiver.com/?p=123</guid>
		<description><![CDATA[
Ontem e hoje eu passei o dia desenvolvendo uma pequena aplicaÃ§Ã£o com o CakePHP. Foi a primeira que eu efetivamente concluÃ­. :P
Esses dias, houve uma grande promoÃ§Ã£o de CDs na Submarino, no meio de tanto cd interessante, deixei de comprar alguns simplesmente pq eu nÃ£o lembrava se eu jÃ¡ tinha ou nÃ£o. Por mais bizarro [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="size-full wp-image-122 alignnone" title="Lista de CDs &amp; DVDs" src="http://blog.cleiver.com/wp-content/uploads/2008/11/lista.jpg" alt="Lista de CDs &amp; DVDs" width="394" height="276" /></p>
<p>Ontem e hoje eu passei o dia desenvolvendo uma pequena aplicaÃ§Ã£o com o CakePHP. Foi a primeira que eu efetivamente concluÃ­. :P</p>
<p>Esses dias, houve uma grande promoÃ§Ã£o de CDs na Submarino, no meio de tanto cd interessante, deixei de comprar alguns simplesmente pq eu nÃ£o lembrava se eu jÃ¡ tinha ou nÃ£o. Por mais bizarro que isso possa ser para alguns, eu costumo nÃ£o lembrar os cds que tenho. :P EntÃ£o ele basicamente me diz isso e pronto, acabou.</p>
<p>Desenvolver com o Cake foi bem tranquilo, continuo nÃ£o me agradando do Form Helper, mas o utilizei da mesma forma. Primeiro fiz a parte de programaÃ§Ã£o, comecei ontem depois do almoÃ§o e terminei ontem mesmo. Hoje passei o dia todo somente fazendo o layout. :O</p>
<p>Obviamente esse &#8220;projeto&#8221; nÃ£o Ã© aberto ao pÃºblico, uma vez que o fiz somente para controlar meus CDs, mas quem sabe nÃ£o vai rolando uns upgrades no futuro? ;P</p>


<p>Posts Relacionados:<ol><li><a href='http://blog.cleiver.com/2009/09/17/updates/' rel='bookmark' title='Permanent Link: Updates'>Updates</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.cleiver.com/2008/11/12/micro-projeto-em-cakephp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CakePHP e seu form Helper</title>
		<link>http://blog.cleiver.com/2008/10/28/cakephp-e-seu-form-helper/</link>
		<comments>http://blog.cleiver.com/2008/10/28/cakephp-e-seu-form-helper/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 18:48:11 +0000</pubDate>
		<dc:creator>Cleiver</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.cleiver.com/?p=109</guid>
		<description><![CDATA[Utilizar os Helpers ajudam e facilitam muito o desenvolvimento, isso todo mundo deve saber. Mas uma coisa que me incomoda bastante Ã© o cÃ³digo automÃ¡tico gerado algumas vezes. Eu tenho sindrome de Deus e gosto de ter controle de tudo, o que nÃ£o Ã© possÃ­vel as vezes utilizando o Form Helper.
Por exemplo, vamos criar um [...]]]></description>
			<content:encoded><![CDATA[<p>Utilizar os Helpers ajudam e facilitam muito o desenvolvimento, isso todo mundo deve saber. Mas uma coisa que me incomoda bastante Ã© o cÃ³digo automÃ¡tico gerado algumas vezes. Eu tenho sindrome de Deus e gosto de ter controle de tudo, o que nÃ£o Ã© possÃ­vel as vezes utilizando o Form Helper.</p>
<p>Por exemplo, vamos criar um formulÃ¡rio com o campo <strong>username</strong> e brincar com ele. Basicamente, seria um formulÃ¡rio para cadastrar usernames em um sistema. Na view <strong>add.ctp</strong> temos o seguinte cÃ³digo:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>create<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'User'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>input<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>end<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Save'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ele vai gerar o seguinte HTML no navegador:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;input text&quot;</span>&gt;</span>
   <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UserUsername&quot;</span>&gt;</span>Username<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UserUsername&quot;</span> <span style="color: #000066;">maxlength</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;data[User][username]&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Se eu tiver algum erro na validaÃ§Ã£o dos dados (feitos no model), a mensagem de erro serÃ¡ exibida abaixo no input.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;input text&quot;</span>&gt;</span>
   <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UserUsername&quot;</span>&gt;</span>Username<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UserUsername&quot;</span> <span style="color: #000066;">maxlength</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;data[User][username]&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;error-message&quot;</span>&gt;</span>Username required!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Mas, e se eu quiser essa mensagem de erro em outro lugar? Em cima do input, por exemplo? E se eu nÃ£o quiser esse label? Supondo que eu queira exibir somente o input e a mensgem de erro em cima dela, tenho que fazer o seguinte:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>input<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span>false<span style="color: #339933;">,</span> <span style="color: #0000ff;">'div'</span><span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span>false<span style="color: #339933;">,</span> <span style="color: #0000ff;">'error'</span><span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span>false<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Coloco a mensagem de erro onde eu quiser atravÃ©s do mÃ©todo <strong>error</strong>. Depois oculto as tags que nÃ£o quero na criaÃ§Ã£o do input. A div estou ocultando por causa da semÃ¢ntica, senÃ£o a mensagem de erro ficaria do lado de fora da div que contÃ©m o input. Estou setando o error do input como false pq senÃ£o alÃ©m dele exibir a mensagem atravÃ©s do mÃ©todo error, ele tambÃ©m ira criar a div com o erro embaixo do input, ficando assim duas mensagens.</p>
<p>Deve ter uma soluÃ§Ã£o melhor para casos assim, mas como nÃ£o encontrei nada na minha pesquisa, tive que dar meu jeito.</p>


<p>Nenhum post relacionado.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.cleiver.com/2008/10/28/cakephp-e-seu-form-helper/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CakePHP e o Banco de Dados</title>
		<link>http://blog.cleiver.com/2008/10/23/cakephp-e-o-banco-de-dados/</link>
		<comments>http://blog.cleiver.com/2008/10/23/cakephp-e-o-banco-de-dados/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 21:51:01 +0000</pubDate>
		<dc:creator>Cleiver</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.cleiver.com/?p=101</guid>
		<description><![CDATA[Quem mexe com o CakePHP jÃ¡ deve ter percebido que ele &#8220;exige&#8221; uma conexÃ£o com um Banco de Dados, mesmo se vocÃª nÃ£o for precisar de um. Criar um banco de dados vazio sÃ³ pra constar e deixar o Cake feliz Ã© tosco. Mas mais tosca ainda foi a Ãºnica soluÃ§Ã£o que encontrei pesquisando pela [...]]]></description>
			<content:encoded><![CDATA[<p>Quem mexe com o <a title="CakePHP framework" href="http://www.cakephp.org" target="_blank">CakePHP</a> jÃ¡ deve ter percebido que ele &#8220;exige&#8221; uma conexÃ£o com um Banco de Dados, mesmo se vocÃª nÃ£o for precisar de um. Criar um banco de dados vazio sÃ³ pra constar e deixar o Cake feliz Ã© tosco. Mas mais tosca ainda foi a Ãºnica soluÃ§Ã£o que encontrei pesquisando pela internet: Criar um driver de conexÃ£o prÃ³prio para enganar o Cake!</p>
<p>O primeiro passo seria criar um arquivo, por exemplo, dbo_sem_bd.php na pasta app/models/datasources/dbo/ com o seguinte cÃ³digo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> DboSemBd <span style="color: #000000; font-weight: bold;">extends</span> DboSource <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">function</span> connect<span style="color: #009900;">&#40;</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;">connected</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connected</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #000000; font-weight: bold;">function</span> disconnect<span style="color: #009900;">&#40;</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;">connected</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connected</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Depois, bastava alterar o arquivo database.php na pasta app/config e dizer que o driver utilizado nas conexÃµes serÃ¡ o sem_db. E pra finalizar com chave de outro, em cada model do sistema, setar a variÃ¡vel $useTable como FALSE.</p>
<p>Eu sinceramente prefiro criar um banco de dados vazio e deixar pra lÃ¡, mas o que me deixa mais espantado Ã© o fato de uma ferramenta tÃ£o cheia de recursos quanto o CakePHP nÃ£o tenha uma opÃ§Ã£o onde eu possa colocar que nÃ£o vou utilizar um banco de dados.</p>
<p>Uma outra &#8220;soluÃ§Ã£o&#8221;, e aqui posso estar falando besteira jÃ¡ que nÃ£o vi isso a fundo, seria criar todas as pÃ¡ginas dentro da pasta pages. Mas ai eu teria que criar rotas para todos os meus arquivos para nÃ£o ter que chamar sempre esse controller (pages) na url. Isso tambÃ©m geraria um trabalho tosco.</p>


<p>Nenhum post relacionado.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.cleiver.com/2008/10/23/cakephp-e-o-banco-de-dados/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utilizando o ACL no CakePHP</title>
		<link>http://blog.cleiver.com/2008/09/18/utilizando-o-acl-no-cakephp/</link>
		<comments>http://blog.cleiver.com/2008/09/18/utilizando-o-acl-no-cakephp/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 14:43:22 +0000</pubDate>
		<dc:creator>Cleiver</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[acl]]></category>
		<category><![CDATA[dicas]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.cleiver.com/?p=84</guid>
		<description><![CDATA[Estamos comeÃ§ando um novo projeto aqui na empresa e para ele decidimos usar o CakePHP como framework de desenvolvimento. Desde semana passada estou estudando a utilizaÃ§Ã£o do ACL para controle de acesso Ã s pÃ¡ginas do sistema, mas como muitos devem saber, o book do site do Cake nÃ£o Ã© tÃ£o explicativo quanto deveria. :P
Quer [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cakephp.org" target="_blank"><img class="size-full wp-image-85" title="CakePHP" src="http://blog.cleiver.com/wp-content/uploads/2008/09/cake-logo.png" alt="CakePHP" width="180" height="180" align="left" /></a>Estamos comeÃ§ando um novo projeto aqui na empresa e para ele decidimos usar o <a title="CakePHP Framework" href="http://cakephp.org" target="_blank">CakePHP</a> como framework de desenvolvimento. Desde semana passada estou estudando a utilizaÃ§Ã£o do ACL para controle de acesso Ã s pÃ¡ginas do sistema, mas como muitos devem saber, o <a title="Cook Book" href="http://book.cakephp.org/" target="_blank">book</a> do site do Cake nÃ£o Ã© tÃ£o explicativo quanto deveria. :P</p>
<p>Quer dizer, o <a title="The Lord of the Rings baking a cake! :P" href="http://book.cakephp.org/view/465/Understanding-How-ACL-Works" target="_blank">exemplo do conceito sendo explicado utilizando os personagens d&#8217;O Senhor dos AnÃ©is</a> Ã© sensacional! Mas sÃ³ serve pra isso mesmo, explicar o conceito. Por que na prÃ¡tica, a coisa Ã© um pouco mais complexa.</p>
<p>Pra tentar entender o funcionamento, criei o <a title="Exemplo simples de blog com CakePHP" href="http://book.cakephp.org/view/219/Blog" target="_blank">blog de exemplo</a> do prÃ³prio &#8220;<a title="Cook Book :P" href="http://book.cakephp.org/" target="_blank">Livro de Receitas</a>&#8221; do CakePHP. PorÃ©m ele Ã© simples demais e nem tem usuÃ¡rios. EntÃ£o criei uma tabela para armazenar somente um login e senha de acesso. Nada muito difÃ­cil para quem jÃ¡ mexeu com o  Cake pelo menos uma vez.</p>
<p>AÃ­ vem outro problema: por padrÃ£o, o ACL vem pronto pra trabalhar com CRUD, e dificilmente teremos um sistema que sÃ³ utilize os mÃ©todos do CRUD. O que fazer entÃ£o? Depois de dias lendo documentaÃ§Ã£o sobre o assunto, chegou atÃ© mim um texto (perdi o link, desculpem. :/) que dizia, resumidamente, que era sÃ³ associar os actions como ACOs normalmente, e na hora de salvar no banco, dar acesso total nos</p>
<p>EntÃ£o, supondo que esteja tudo pronto, vamos resolver o grande problema que encontrei nos blogs que li: Os mÃ©todos de criaÃ§Ã£o dos AROs e dos ACOs, bem como seus relacionamentos, <span style="text-decoration: underline;"><em><strong>nÃ£o devem ficar espalhados pela aplicaÃ§Ã£o</strong></em></span>. Crie um arquivo PHP separado para executar somente quando vocÃª precisar popular o banco de dados com as informaÃ§Ãµes de acesso.</p>
<p>EntÃ£o vamos comeÃ§ar criando um pequeno script que cria os AROs do nosso &#8220;sistema&#8221;:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$aro</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> aro<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$groups</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
   <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Admins'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Authors'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Spammers'</span> <span style="color: #009900;">&#41;</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;">$groups</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$group</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$aro</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$aro</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$group</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Esse script vai gerar grupos de usuÃ¡rios do sistema. temos os administradores, os autores do blog e spammers, que sÃ£o usuÃ¡rios que nÃ£o terÃ£o acesso a nada.</p>
<p>Agora vamos criar alguns usuÃ¡rios:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$aro</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> aro<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$users</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
   <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> Pedro<span style="color: #339933;">,</span> <span style="color: #0000ff;">'parent_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'foreign_key'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> Rafael<span style="color: #339933;">,</span> <span style="color: #0000ff;">'parent_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'foreign_key'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> Adriana<span style="color: #339933;">,</span> <span style="color: #0000ff;">'parent_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'foreign_key'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</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;">$users</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$user</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$aro</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$aro</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Acima estou criando 3 usuÃ¡rios apenas, um para cada grupo. O campo <strong>parent_id</strong> aponta para o grupo que o usuÃ¡rio faz parte. O campo <strong>model</strong>, como o prÃ³prio nome diz, especifica um modelo. No caso, ele guarda o nome do modelo que o id armazenado em <strong>foreign_key</strong> pertence. EntÃ£o no exemplo acima, o id do Pedro na tabela User Ã© 1.</p>
<p>Agora vamos criar algumas ACOs:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$aco</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> aco<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$group</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Post'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$aco</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$aco</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$group</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$actions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
   <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'parent_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'view'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'parent_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'add'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'parent_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #cc66cc;">3</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'delete'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'parent_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #cc66cc;">4</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alias'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'edit'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'parent_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</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;">$actions</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$action</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$aco</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$aco</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$action</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>O processo para criaÃ§Ã£o Ã© exatamente o mesmo do utilizado no ARO. Aqui, primeiro criei um grupo com o nome do prÃ³prio controller, assim fica mais fÃ¡cil organizar. Depois, criei uma ACO para cada action do controller e as relacionei com o grupo criado anteriormente.</p>
<p>Se vocÃª nÃ£o definir nenhum tipo de permissÃ£o de acesso, por padrÃ£o, Ã© tudo negado. EntÃ£o vamos definir algumas permissÃµes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allow</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Admins'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'Post'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'*'</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;">Acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allow</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Authors'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'Post'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'*'</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;">Acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deny</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Authors'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'Post/delete'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'*'</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;">Acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deny</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Spammers'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'Post'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'*'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Na primeira linha, dei acesso total Ã  todas as actions do controller Post para os usuÃ¡rios que fizerem parte do grupo Admins. Na segunda linha, dei acesso total tambÃ©m aos autores do blog, mas na terceira eu tirei a permissÃ£o deles de deletar algum post, ou seja, eles podem tudo, menos deletar o texto que escreveram. Assim Ã© mais fÃ¡cil do que ficar fazendo um allow para cada action do controller. Na quarta linha tirei a permissÃ£o de acesso Ã  todas as actions do controller para quem for do grupo spammers.</p>
<p>Para verificar quem tem acesso ou nÃ£o, dentro do seu controller, no mÃ©todo beforeFilter por exemplo, basta fazer o seguinte:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Authors'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'Post/delete'</span> <span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>No nosso caso vai retornar FALSE.</p>
<p>Basicamente Ã© isso. Tem outras coisas interessantes para se trabalhar junto com o ACL, como o <a title="ACL Behavior" href="http://lemoncake.wordpress.com/2007/07/15/using-aclbehavior-in-cakephp-12/" target="_blank">ACLBehavior</a> e o <a title="ACL Management Plugin" href="http://jeff.loiselles.com/wordpress/?p=28" target="_blank">ACL Management Plugin</a>. Uma boa leitura que pode ajudar um bocado Ã© esse <a href="http://aranworld.com/article/161/cakephp-acl-tutorial-what-is-it" target="_blank">tutorial</a> de utilizaÃ§Ã£o que um cara fez pro caso dele, tem atÃ© um sitezinho de exemplo.</p>


<p>Nenhum post relacionado.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.cleiver.com/2008/09/18/utilizando-o-acl-no-cakephp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
