<?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>work in progress ... &#187; ezcMvcCatchallRoute</title>
	<atom:link href="http://blog.tobias-olry.de/tag/ezcmvccatchallroute/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.tobias-olry.de</link>
	<description>... Stillstand gibt's nicht! (von Tobias Olry)</description>
	<lastBuildDate>Thu, 24 Sep 2009 06:44:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>extending ezcMvcCatchallRoute</title>
		<link>http://blog.tobias-olry.de/extending-ezcmvccatchallroute</link>
		<comments>http://blog.tobias-olry.de/extending-ezcmvccatchallroute#comments</comments>
		<pubDate>Tue, 01 Sep 2009 05:31:21 +0000</pubDate>
		<dc:creator>Tobias</dc:creator>
				<category><![CDATA[all]]></category>
		<category><![CDATA[ezcMvcCatchallRoute]]></category>
		<category><![CDATA[ezcMvcTools]]></category>
		<category><![CDATA[ezComponents]]></category>
		<category><![CDATA[Linux Desktop]]></category>
		<category><![CDATA[Open-Source]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.tobias-olry.de/?p=70</guid>
		<description><![CDATA[<p>I am currently working on a private project and while at it, giving ezvMvcTools a shot. I&#8217;m a big fan of ezComponents and using ezcMail and ezcGraph on a regular basis. So far, ezcMvcTools looks like an interesting MVC implementation with some differences to the typical ones I&#8217;ve used by now.</p>
<p></p>
<p>While adapting the hello world [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working on a private project and while at it, giving ezvMvcTools a shot. I&#8217;m a big fan of ezComponents and using <a title="ezcMail Tutorial" href="http://www.ezcomponents.org/docs/tutorials/Mail">ezcMail</a> and <a title="ezcGraph Tutorial" href="http://www.ezcomponents.org/docs/tutorials/Graph">ezcGraph</a> on a regular basis. So far, ezcMvcTools looks like an interesting MVC implementation with some differences to the typical ones I&#8217;ve used by now.</p>
<p><span id="more-70"></span></p>
<p>While adapting the <a title="ezcMvcTools Hello World Application" href="http://www.ezcomponents.org/docs/tutorials/MvcTools#a-simple-application-hello-world">hello world application</a> to my needs I ran into some trouble: Since I am pretty lazy and used to comfortable routing from my other MVC symfony, I didn&#8217;t want to set every single route manually. So I found ezcMvcCatchallRoute which maps  URLs of  &#8220;/&lt;controller&gt;/&lt;action&gt;&#8221; automatically, just what I wanted. Only problem was, the url-part &#8220;&lt;controller&gt;&#8221; was translated to the  classname &#8220;&lt;controller&gt;Controller&#8221; and had no option to add some prefix to this.</p>
<p>There was a prefix-option, but this was meant for route-prefixing ( e.g. if you wanted the route to match all routes that look like &#8220;/seo&lt;Controller&gt;/&lt;action&gt;&#8221;).</p>
<p>But it was quite easy to extend the function to fit my needs, so every controller classname would be prefixed with my project&#8217;s class-prefix:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> portfolioCatchAllRoute <span style="color: #000000; font-weight: bold;">extends</span> ezcMvcCatchAllRoute
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     *
     * @var string
     */</span>
    protected <span style="color: #000088;">$controllerNamePrefix</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     *
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getControllerNamePrefix<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controllerNamePrefix</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     *
     * @param string $controllerNamePrefix
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setControllerNamePrefix<span style="color: #009900;">&#40;</span><span style="color: #000088;">$controllerNamePrefix</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>controllerNamePrefix <span style="color: #339933;">=</span> <span style="color: #000088;">$controllerNamePrefix</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     *
     * overload ezcMvcCatchAllRoute::createControlllerName() to make use of controllerNamePrefix
     *
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> createControllerName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$controllerName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getControllerNamePrefix</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">ucfirst</span><span style="color: #009900;">&#40;</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">createControllerName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$controllerName</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>usage in your router:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> portfolioRouter <span style="color: #000000; font-weight: bold;">extends</span> ezcMvcRouter
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> createRoutes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$catchallRoute</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> portfolioCatchAllRoute<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$catchallRoute</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setControllerNamePrefix</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'portfolio'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #000088;">$catchallRoute</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.tobias-olry.de/extending-ezcmvccatchallroute/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
