<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: An alternative approach for static pages</title>
	<atom:link href="http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Sat, 13 Mar 2010 15:19:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: John</title>
		<link>http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/comment-page-1/#comment-127567</link>
		<dc:creator>John</dc:creator>
		<pubDate>Mon, 11 May 2009 09:41:08 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=615#comment-127567</guid>
		<description>@cakebaker

Hi - in the end I have left my routes as they were originally and I have extended the paginator helper. 

In the extended paginator helper I&#039;ve over-ridden the link() method and am building the url directly using the data that was passed to the view in $this-&gt;passedArgs as a basis.

Thanks for your ideas.</description>
		<content:encoded><![CDATA[<p>@cakebaker</p>
<p>Hi &#8211; in the end I have left my routes as they were originally and I have extended the paginator helper. </p>
<p>In the extended paginator helper I&#8217;ve over-ridden the link() method and am building the url directly using the data that was passed to the view in $this-&gt;passedArgs as a basis.</p>
<p>Thanks for your ideas.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/comment-page-1/#comment-127378</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Fri, 08 May 2009 15:01:00 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=615#comment-127378</guid>
		<description>@John: If the extra routes follow the same pattern you could generate those routes with a foreach loop. Technically, you will still have 15 extra routes, but at least it is more compact. 

It&#039;s just an idea, I don&#039;t know whether that&#039;s practical in your specific situation...</description>
		<content:encoded><![CDATA[<p>@John: If the extra routes follow the same pattern you could generate those routes with a foreach loop. Technically, you will still have 15 extra routes, but at least it is more compact. </p>
<p>It&#8217;s just an idea, I don&#8217;t know whether that&#8217;s practical in your specific situation&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/comment-page-1/#comment-127290</link>
		<dc:creator>John</dc:creator>
		<pubDate>Thu, 07 May 2009 15:40:54 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=615#comment-127290</guid>
		<description>@cakebaker - I am reluctantly coming to the same conclusion after digging around in the API a lot, the thing is it is more like 15 extra routes not 2... 

I think I may just leave it with my original routes solution and just write a custom pagination element for the single instance where the problem occurs.

Perhaps this is just one of those small annoyances I&#039;ll just have to live with, sometimes workarounds are where its at.

John</description>
		<content:encoded><![CDATA[<p>@cakebaker &#8211; I am reluctantly coming to the same conclusion after digging around in the API a lot, the thing is it is more like 15 extra routes not 2&#8230; </p>
<p>I think I may just leave it with my original routes solution and just write a custom pagination element for the single instance where the problem occurs.</p>
<p>Perhaps this is just one of those small annoyances I&#8217;ll just have to live with, sometimes workarounds are where its at.</p>
<p>John</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/comment-page-1/#comment-127289</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Thu, 07 May 2009 15:24:21 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=615#comment-127289</guid>
		<description>@John: Hm, I don&#039;t know whether it is possible to write this as a single route. As a workaround I would simply define two additional routes for those routes you don&#039;t want to handle with the &quot;catch all&quot; route. 

Maybe it is worth an enhancement ticket?

Hope that helps!</description>
		<content:encoded><![CDATA[<p>@John: Hm, I don&#8217;t know whether it is possible to write this as a single route. As a workaround I would simply define two additional routes for those routes you don&#8217;t want to handle with the &#8220;catch all&#8221; route. </p>
<p>Maybe it is worth an enhancement ticket?</p>
<p>Hope that helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/comment-page-1/#comment-127268</link>
		<dc:creator>John</dc:creator>
		<pubDate>Thu, 07 May 2009 08:44:09 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=615#comment-127268</guid>
		<description>Hi All

I&#039;ve been using the variant below (first posted here by panther40k I think) (different controller / action obviously)
&lt;code&gt;
$Route-&gt;connect(’(?!admin&#124;function)(.*)’, array(’controller’ =&gt; ‘nodes’, ‘action’ =&gt; ‘view’)); 
&lt;/code&gt;
for ages in 1.2 without any problems... until now. The problem is a bit long winded and is described on groups here: http://groups.google.com/group/cake-php/browse_thread/thread/9e295aefeeeb3eb8?hl=en

Anyway what I am trying to do is rewrite the above route in a proper Cake 1.2 way e.g. 
&lt;code&gt;
Router::connect(
        &#039;/*&#039;,
        array(
                &#039;controller&#039; =&gt; &#039;nodes&#039;,
                &#039;action&#039; =&gt; &#039;view&#039;,

        ),
        array(&#039;*&#039;  =&gt; &#039;(?!admin&#124;products)&#039;) 
);

But it doesn&#039;t quite work - so /products/options/146 is still getting routed to /nodes/view 

What I am trying to do is have * parsed as a named parameter. Any ideas anyone?</description>
		<content:encoded><![CDATA[<p>Hi All</p>
<p>I&#8217;ve been using the variant below (first posted here by panther40k I think) (different controller / action obviously)<br />
<code>$Route-&gt;connect(’(?!admin|function)(.*)’, array(’controller’ =&gt; ‘nodes’, ‘action’ =&gt; ‘view’));</code><br />
for ages in 1.2 without any problems&#8230; until now. The problem is a bit long winded and is described on groups here: <a href="http://groups.google.com/group/cake-php/browse_thread/thread/9e295aefeeeb3eb8?hl=en" rel="nofollow">http://groups.google.com/group/cake-php/browse_thread/thread/9e295aefeeeb3eb8?hl=en</a></p>
<p>Anyway what I am trying to do is rewrite the above route in a proper Cake 1.2 way e.g.<br />
<code><br />
Router::connect(<br />
        '/*',<br />
        array(<br />
                'controller' =&gt; 'nodes',<br />
                'action' =&gt; 'view',</p>
<p>        ),<br />
        array('*'  =&gt; '(?!admin|products)')<br />
);</p>
<p>But it doesn't quite work - so /products/options/146 is still getting routed to /nodes/view </p>
<p>What I am trying to do is have * parsed as a named parameter. Any ideas anyone?</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/comment-page-1/#comment-126797</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Fri, 01 May 2009 06:40:24 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=615#comment-126797</guid>
		<description>@Arne: Thanks for this addition!</description>
		<content:encoded><![CDATA[<p>@Arne: Thanks for this addition!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arne Diekmann</title>
		<link>http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/comment-page-1/#comment-126496</link>
		<dc:creator>Arne Diekmann</dc:creator>
		<pubDate>Mon, 27 Apr 2009 14:09:35 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=615#comment-126496</guid>
		<description>Hey!

Thanks for the snippet, its very elegant! The only problem for me was the fact that I made heavy use of the theme-option in cakephp. 3 more lines and thats working also though:

&lt;code&gt;
&lt;?php 

class PagesController extends AppController
{

    public $uses = array();

    public function display()
    {

        $view_filename = array_pop($this-&gt;params[&#039;pass&#039;]) . &#039;.ctp&#039;;
        $view_filename = str_replace(&#039;-&#039;, &#039;_&#039;, $view_filename);
        $view_path =  DS . $view_filename;

        if ($this-&gt;params[&#039;pass&#039;])
        {

            $view_path = DS . implode(DS, $this-&gt;params[&#039;pass&#039;]) . $view_path;

        }

        if (isset($this-&gt;theme) &amp;&amp; file_exists(VIEWS . &#039;themed&#039; . DS . $this-&gt;theme . DS . &#039;pages&#039; . $view_path))
        {

            $this-&gt;render(null, null, VIEWS . &#039;themed&#039; . DS . $this-&gt;theme . DS . &#039;pages&#039; . $view_path);

        }
        elseif (file_exists(VIEWS . &#039;pages&#039; . $view_path))
        {

            $this-&gt;render(null, null, VIEWS . &#039;pages&#039; . $view_path);

        }
        else
        {

            $this-&gt;cakeError(&#039;error404&#039;);

        }

    }

}

?&gt;
&lt;/code&gt;

Greetings!</description>
		<content:encoded><![CDATA[<p>Hey!</p>
<p>Thanks for the snippet, its very elegant! The only problem for me was the fact that I made heavy use of the theme-option in cakephp. 3 more lines and thats working also though:</p>
<pre><code>&lt;?php 

class PagesController extends AppController
{

    public $uses = array();

    public function display()
    {

        $view_filename = array_pop($this-&gt;params['pass']) . '.ctp';
        $view_filename = str_replace('-', '_', $view_filename);
        $view_path =  DS . $view_filename;

        if ($this-&gt;params['pass'])
        {

            $view_path = DS . implode(DS, $this-&gt;params['pass']) . $view_path;

        }

        if (isset($this-&gt;theme) &amp;&amp; file_exists(VIEWS . 'themed' . DS . $this-&gt;theme . DS . 'pages' . $view_path))
        {

            $this-&gt;render(null, null, VIEWS . 'themed' . DS . $this-&gt;theme . DS . 'pages' . $view_path);

        }
        elseif (file_exists(VIEWS . 'pages' . $view_path))
        {

            $this-&gt;render(null, null, VIEWS . 'pages' . $view_path);

        }
        else
        {

            $this-&gt;cakeError('error404');

        }

    }

}

?&gt;</code></pre>
<p>Greetings!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/comment-page-1/#comment-119849</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Fri, 06 Feb 2009 15:16:15 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=615#comment-119849</guid>
		<description>@brian: Thanks for your comment!

Which CakePHP version do you use? I just copied your route and your $html-&gt;link() statement into my test application (which uses the latest cake version from the repository), and there the reverse routing worked fine, i.e. the generated link points to &quot;/contact&quot;. Is it possible that you added your route after the default pages route (Router::connect(&#039;/pages/*&#039;, array(&#039;controller&#039; =&gt; &#039;pages&#039;, &#039;action&#039; =&gt; &#039;display&#039;));)?</description>
		<content:encoded><![CDATA[<p>@brian: Thanks for your comment!</p>
<p>Which CakePHP version do you use? I just copied your route and your $html-&gt;link() statement into my test application (which uses the latest cake version from the repository), and there the reverse routing worked fine, i.e. the generated link points to &#8220;/contact&#8221;. Is it possible that you added your route after the default pages route (Router::connect(&#8216;/pages/*&#8217;, array(&#8216;controller&#8217; =&gt; &#8216;pages&#8217;, &#8216;action&#8217; =&gt; &#8216;display&#8217;));)?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian (headache)</title>
		<link>http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/comment-page-1/#comment-119500</link>
		<dc:creator>brian (headache)</dc:creator>
		<pubDate>Wed, 04 Feb 2009 04:42:16 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=615#comment-119500</guid>
		<description>I like this technique very much. I do think it&#039;s better than the AppError technique. I&#039;ve had a very good system for a while now but wanted to move all my links to use routing arrays. Unfortunately, they always include that &#039;pages&#039; bit. It doesn&#039;t make sense to me that, if I have a route like this:

Router::connect(&#039;/contact&#039;, array(&#039;controller&#039; =&gt; &#039;pages&#039;, &#039;action&#039; =&gt; &#039;display&#039;, &#039;contact&#039;));

... and I create a link like this:

$html-&gt;link(
	&#039;Contact&#039;, 
	array(&#039;controller&#039; =&gt; &#039;pages&#039;, &#039;action&#039; =&gt; &#039;display&#039;, &#039;contact&#039;),
	array(&#039;title&#039; =&gt; &#039;How to contact us&#039;)
)

.. I get a link like &quot;/pages/contact&quot;. If I can use custom routes for other controllers, it should be possible here, also. Very strange.

With your technique, using reverse routing is again out of the question, but it&#039;s cleaner than what I&#039;ve been using, so I think I&#039;ll upgrade.

I made a change to display() in order to have deeper levels without having to specify &quot;index&#039; for the default page.

eg. &#039;/about&#039; or &#039;/about/&#039; will display &#039;views/pages/about/index.ctp&#039;

public function display()
{
	$viewFilename = str_replace(&#039;-&#039;, &#039;_&#039;, array_pop($this-&gt;params[&#039;pass&#039;]));
	
	$viewPath =  DS . $viewFilename;
	if ($this-&gt;params[&#039;pass&#039;])
	{
		$viewPath = DS . implode(DS, $this-&gt;params[&#039;pass&#039;]) . $viewPath;
	}
	
	if (file_exists(VIEWS.&#039;pages&#039;.$viewPath.&#039;.ctp&#039;))
	{
		$this-&gt;render(null, null, VIEWS.&#039;pages&#039;.$viewPath . &#039;.ctp&#039;);
	}
	else if (file_exists(VIEWS.&#039;pages&#039;.$viewPath.DS.&#039;index.ctp&#039;))
	{
		$this-&gt;render(null, null, VIEWS.&#039;pages&#039;.$viewPath.DS.&#039;index.ctp&#039;);
	}
	else
	{
		$this-&gt;cakeError(&#039;error404&#039;);
	}
}

I removed the &#039;.ctp&#039; append to $viewPath so that it isn&#039;t in the way in the &quot;else if&quot; test.</description>
		<content:encoded><![CDATA[<p>I like this technique very much. I do think it&#8217;s better than the AppError technique. I&#8217;ve had a very good system for a while now but wanted to move all my links to use routing arrays. Unfortunately, they always include that &#8216;pages&#8217; bit. It doesn&#8217;t make sense to me that, if I have a route like this:</p>
<p>Router::connect(&#8216;/contact&#8217;, array(&#8216;controller&#8217; =&gt; &#8216;pages&#8217;, &#8216;action&#8217; =&gt; &#8216;display&#8217;, &#8216;contact&#8217;));</p>
<p>&#8230; and I create a link like this:</p>
<p>$html-&gt;link(<br />
	&#8216;Contact&#8217;,<br />
	array(&#8216;controller&#8217; =&gt; &#8216;pages&#8217;, &#8216;action&#8217; =&gt; &#8216;display&#8217;, &#8216;contact&#8217;),<br />
	array(&#8216;title&#8217; =&gt; &#8216;How to contact us&#8217;)<br />
)</p>
<p>.. I get a link like &#8220;/pages/contact&#8221;. If I can use custom routes for other controllers, it should be possible here, also. Very strange.</p>
<p>With your technique, using reverse routing is again out of the question, but it&#8217;s cleaner than what I&#8217;ve been using, so I think I&#8217;ll upgrade.</p>
<p>I made a change to display() in order to have deeper levels without having to specify &#8220;index&#8217; for the default page.</p>
<p>eg. &#8216;/about&#8217; or &#8216;/about/&#8217; will display &#8216;views/pages/about/index.ctp&#8217;</p>
<p>public function display()<br />
{<br />
	$viewFilename = str_replace(&#8216;-&#8217;, &#8216;_&#8217;, array_pop($this-&gt;params['pass']));</p>
<p>	$viewPath =  DS . $viewFilename;<br />
	if ($this-&gt;params['pass'])<br />
	{<br />
		$viewPath = DS . implode(DS, $this-&gt;params['pass']) . $viewPath;<br />
	}</p>
<p>	if (file_exists(VIEWS.&#8217;pages&#8217;.$viewPath.&#8217;.ctp&#8217;))<br />
	{<br />
		$this-&gt;render(null, null, VIEWS.&#8217;pages&#8217;.$viewPath . &#8216;.ctp&#8217;);<br />
	}<br />
	else if (file_exists(VIEWS.&#8217;pages&#8217;.$viewPath.DS.&#8217;index.ctp&#8217;))<br />
	{<br />
		$this-&gt;render(null, null, VIEWS.&#8217;pages&#8217;.$viewPath.DS.&#8217;index.ctp&#8217;);<br />
	}<br />
	else<br />
	{<br />
		$this-&gt;cakeError(&#8216;error404&#8242;);<br />
	}<br />
}</p>
<p>I removed the &#8216;.ctp&#8217; append to $viewPath so that it isn&#8217;t in the way in the &#8220;else if&#8221; test.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/06/18/an-alternative-approach-for-static-pages/comment-page-1/#comment-101575</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Mon, 04 Aug 2008 15:45:09 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=615#comment-101575</guid>
		<description>@Herod: Thanks for your comment!

Well, the DS is required so that $viewPath always starts with a DS (which is needed for the file_exists check I used in the article). But if you remove the &quot;pages&quot; from the file_exists call, then you are right, and the DS is not needed.</description>
		<content:encoded><![CDATA[<p>@Herod: Thanks for your comment!</p>
<p>Well, the DS is required so that $viewPath always starts with a DS (which is needed for the file_exists check I used in the article). But if you remove the &#8220;pages&#8221; from the file_exists call, then you are right, and the DS is not needed.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
