<?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>Blog cakephp en español por Hospedaxes &#187; panel</title>
	<atom:link href="http://cakephp.hospedaxes.com/tag/panel/feed" rel="self" type="application/rss+xml" />
	<link>http://cakephp.hospedaxes.com</link>
	<description>Blog sobre desarrollo web con cakephp en español por Hospedaxes</description>
	<lastBuildDate>Mon, 26 Apr 2010 07:11:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Separación de funcionalidades (similar a fachadas)</title>
		<link>http://cakephp.hospedaxes.com/separacion-de-funcionalidades-similar-a-fachadas</link>
		<comments>http://cakephp.hospedaxes.com/separacion-de-funcionalidades-similar-a-fachadas#comments</comments>
		<pubDate>Fri, 18 Apr 2008 06:56:02 +0000</pubDate>
		<dc:creator>nuria</dc:creator>
				<category><![CDATA[Noticias]]></category>
		<category><![CDATA[cakephp-1.2]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[administrador]]></category>
		<category><![CDATA[estructura]]></category>
		<category><![CDATA[fachadas]]></category>
		<category><![CDATA[organizacion]]></category>
		<category><![CDATA[panel]]></category>
		<category><![CDATA[separacion funcionalidades]]></category>

		<guid isPermaLink="false">http://www.hospedaxes.com/blog-cakephp/?p=7</guid>
		<description><![CDATA[CakePHP 1.2 nos proporciona un soporte con un significado similar al de las fachadas, que nos permite:

Separar los distintos tipos de funcionalidades en los controladores: podemos separar, por ejemplo, las funciones que corresponden al administrador, del resto de las funciones, simplemente iniciando el nombre de dicha función con la cadena "admin_".
Separar por urls los distintos [...]]]></description>
			<content:encoded><![CDATA[<p>CakePHP 1.2 nos proporciona un soporte con un significado similar al de las fachadas, que nos permite:</p>
<ul>
<li>Separar los distintos tipos de funcionalidades en los controladores: podemos separar, por ejemplo, las funciones que corresponden al administrador, del resto de las funciones, simplemente iniciando el nombre de dicha función con la cadena "admin_".</li>
<li>Separar por urls los distintos apartados: por ejemplo, para acceder a una función de un controlador que sea "admin_listar", tendremos que escribir la url: admin/controlador/listar. De esta forma sabemos en todo momento en qué parte de nuestro proyecto nos movemos.</li>
<li>Como consecuencia y para que nuestro proyecto mucho más organizado, separaremos también las vistas en función de si estamos en la sección del administrador o en las otras secciones.</li>
<li>Esto nos permitirá también realizar un tratamiento personalizado de cada sección: por ejemplo, en el <em>beforeFilter</em> del <em>AppController</em> le podemos introducir un filtro de login.</li>
</ul>
<p>Veamos cómo realizar la configuración de todo lo comentado. En el archivo <em>app/config/routes.php</em>, escribimos:</p>
<div class="igBar"><span id="lphp-4"><a href="#" onclick="javascript:showPlainTxt('php-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-4">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Configure::<span style="color:#006600;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Routing.admin'</span>, <span style="color:#FF0000;">'admin'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
En el controlador:</p>
<div class="igBar"><span id="lphp-5"><a href="#" onclick="javascript:showPlainTxt('php-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-5">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">class</span> UsuariosController extends AppController</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$layout</span> = <span style="color:#FF0000;">'usuarios'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> admin_listar<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#FF9933; font-style:italic;">//Comandos}</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> listar<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#FF9933; font-style:italic;">//Comandos }</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
De esta manera podemos cambiar el layout en función de dónde nos encontremos y tenerlas estructuradas en distintas carpetas. Para ello, en el archivo <em>cake/libs/controller/app_controller.php</em> escribimos:</p>
<div class="igBar"><span id="lphp-6"><a href="#" onclick="javascript:showPlainTxt('php-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-6">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">class</span> AppController extends Controller</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> beforeFilter<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'action'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <a href="http://www.php.net/strstr"><span style="color:#000066;">strstr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'action'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#FF0000;">'admin_'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span> = <span style="color:#FF0000;">'admin/'</span>.<span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// O bien, comparando una variable que se almacena en &lt;em&gt;$this-&gt;data&lt;/em&gt;:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'admin'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'admin'</span><span style="color:#006600; font-weight:bold;">&#93;</span>==<span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span> = <span style="color:#FF0000;">'admin/'</span>.<span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// La última posibilidad es comparando la variable &lt;em&gt;prefix&lt;/em&gt; de &lt;em&gt;$this-&gt;data&lt;/em&gt;:</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'prefix'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&amp;&amp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'prefix'</span><span style="color:#006600; font-weight:bold;">&#93;</span>==<span style="color:#FF0000;">'admin'</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span> = <span style="color:#FF0000;">'admin/'</span>.<span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Podríamos configurar tantas secciones como queramos simplemente añadiendo más líneas en el archivo <em>routes.php</em>, obteniendo un código mucho más limpio y legible.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/separacion-de-funcionalidades-similar-a-fachadas/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
