<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Dasher's Corner &#187; development tips</title>
	<atom:link href="http://dasher.wordpress.com/tag/development-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://dasher.wordpress.com</link>
	<description>Natural Language &#38; Machine Translation</description>
	<lastBuildDate>Sat, 20 Jun 2009 13:08:28 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='dasher.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/333fa50f89d3d9a1b2eb9aeb6cc7b342?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Dasher's Corner &#187; development tips</title>
		<link>http://dasher.wordpress.com</link>
	</image>
			<item>
		<title>Symfony:  Overloading and Overriding Plugins &amp; Base classes</title>
		<link>http://dasher.wordpress.com/2009/05/15/symfony-overloading-and-overriding-plugins-base-classes/</link>
		<comments>http://dasher.wordpress.com/2009/05/15/symfony-overloading-and-overriding-plugins-base-classes/#comments</comments>
		<pubDate>Fri, 15 May 2009 09:59:46 +0000</pubDate>
		<dc:creator>Dasher</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[dev tips]]></category>
		<category><![CDATA[development tips]]></category>

		<guid isPermaLink="false">http://dasher.wordpress.com/2009/05/15/symfony-overloading-and-overriding-plugins-base-classes/</guid>
		<description><![CDATA[There&#8217;s a couple of places that tend to cause confusion when people try to override Symfony &#38; plugin functionality and the autoloader doesn&#8217;t help when you&#8217;re trying to test things out.
You can generally create your own version of any class &#8211; if you put the new version in the right place and if the file [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dasher.wordpress.com&blog=86394&post=117&subd=dasher&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>There&#8217;s a couple of places that tend to cause confusion when people try to override Symfony &amp; plugin functionality and the autoloader doesn&#8217;t help when you&#8217;re trying to test things out.</p>
<p>You can generally create your own version of any class &#8211; if you put the new version in the right place and if the file and class are named properly.<br />
The location you put the file depends on a number of factors (is it a core module or a plugin) and the scope you want to affect.</p>
<p>With plugins generally the best approach to start is to be as local to your Symfony app as possible.</p>
<ol>
<li>Clear your cache &#8211; it doesn&#8217;t hurt to do this before and after you start making changes and it&#8217;s a good habit to do this often</li>
<li>Start by making a folder for the in apps\&lt;applicationName&gt;\modules\&lt;pluginName&gt; (often you just make the folder rather than using the generator)
<ul>
<li>Depending on what you&#8217;re overloading you create the sub folder here for it &#8211; so if you&#8217;re modifying a template then create a templates folder under the plugin folder you just created</li>
</ul>
</li>
<li>Now copy the existing file from the plugin to the folder you just created- it&#8217;ll be a good starting place to making any changes.  When copying a file it&#8217;s the file that will be used initially by the autoloader  rather than a file named Base….
<ul>
<li>So if you&#8217;re looking to override the actions for sfGuard, it&#8217;s going to be under the sfGuard\modules\sfGuardUser\actions\actions.class.php</li>
<li>Well written plugins will use a base file &#8211; for sfGuard this is BasesfGuardUserActions.class.php &#8211; which allows easy overriding of your own functionality &#8211; you&#8217;ll see a reference to this in the top of the actions file</li>
<li>You&#8217;ll need to change the require/require_once statement in the top of the file you just copied &#8211; to point to the correct place as when you override the autoloader won&#8217;t be able to find the class you&#8217;re trying to include.</li>
<li>This file will generally just be a placeholder &#8211; with all the work being done in the parent class.  You&#8217;ll need to refer to the base class or have a decent IDE that gives you code assist or exploring of the methods in the parent to determine what method signatures are available for you</li>
</ul>
</li>
<li>Now you can implement your own functionality in the file &#8211; for an action start with something simple like overriding a method and putting die(“hey – it worked! – Who’s da man?!?!”).  You can even put this just under the require statement to test &#8211; so you&#8217;ll know that it was your customised file that was included rather than the specific one within the plugin itself.</li>
<li>Clear your cache again and fire up your browser to load a page under the application you used above</li>
<li>Now you see your die statement is being hit – you can implement the actual code you want to happen</li>
</ol>
<p>The locations available for you to put custom classes are:</p>
<ul>
<li>project\apps\thisApp\modules\moduleName\folderType\fileName</li>
<li>project\apps\thisApp\lib\folderType\fileName</li>
<li>project\apps\thisApp\lib\fileName</li>
<li>project\lib\folderType\fileName</li>
<li>project\lib\fileName</li>
</ul>
<p>Where:</p>
<p style="padding-left:30px;">thisApp is your application name<br />
moduleName is the name of your module or the plugin name<br />
folderType is the type of folder – i.e. actions, templates, model, etc<br />
fileName is the name of the file in the expected format (so actions.class.php for the actions class)</p>
<p style="font-size:10px;"><a href="http://posterous.com">Posted via web</a> from <a href="http://blog.inspiredthinking.co.uk/symfony-overloading-and-overriding-plugins-an">Dasher&#8217;s Dev Den</a></p>
Posted in PHP, Symfony, tips Tagged: dev tips, development tips, PHP, Symfony <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dasher.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dasher.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dasher.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dasher.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dasher.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dasher.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dasher.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dasher.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dasher.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dasher.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dasher.wordpress.com&blog=86394&post=117&subd=dasher&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dasher.wordpress.com/2009/05/15/symfony-overloading-and-overriding-plugins-base-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/be5e0c2700dfad20c5981478273d4853?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dasher</media:title>
		</media:content>
	</item>
	</channel>
</rss>