<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Zendcasts Forum - ZC32 - Custom Action Helpers for Firebug]]></title>
	<link rel="self" href="http://www.zendcasts.com/forum/feed/atom/topic/39/"/>
	<updated>2010-01-20T10:59:34Z</updated>
	<generator>PunBB</generator>
	<id>http://www.zendcasts.com/forum/topic/39/zc32-custom-action-helpers-for-firebug/</id>
		<entry>
			<title type="html"><![CDATA[Re: ZC32 - Custom Action Helpers for Firebug]]></title>
			<link rel="alternate" href="http://www.zendcasts.com/forum/post/563/#p563"/>
			<content type="html"><![CDATA[<p>i personally like a lot your english accent with french influences </p><p>especially i like at the beginning of the videos when you pronounce your name (i never understand it:)</p>]]></content>
			<author>
				<name><![CDATA[muscailie]]></name>
			</author>
			<updated>2010-01-20T10:59:34Z</updated>
			<id>http://www.zendcasts.com/forum/post/563/#p563</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: ZC32 - Custom Action Helpers for Firebug]]></title>
			<link rel="alternate" href="http://www.zendcasts.com/forum/post/167/#p167"/>
			<content type="html"><![CDATA[<p>its really good idea to use phpdoc blocks to control your code <br />frankly for me i had never think to use it like this <br />thanks for sharing jon <img src="http://www.zendcasts.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[tawfekov]]></name>
				<uri>http://www.zendcasts.com/forum/user/14/</uri>
			</author>
			<updated>2009-09-08T22:34:52Z</updated>
			<id>http://www.zendcasts.com/forum/post/167/#p167</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: ZC32 - Custom Action Helpers for Firebug]]></title>
			<link rel="alternate" href="http://www.zendcasts.com/forum/post/166/#p166"/>
			<content type="html"><![CDATA[<p>That&#039;s clever, thanks for sharing. I&#039;m disciplined with doc blocks so this fits in nicely with my style. Very cool.</p>]]></content>
			<author>
				<name><![CDATA[ryan.horn]]></name>
				<uri>http://www.zendcasts.com/forum/user/52/</uri>
			</author>
			<updated>2009-09-08T16:18:42Z</updated>
			<id>http://www.zendcasts.com/forum/post/166/#p166</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: ZC32 - Custom Action Helpers for Firebug]]></title>
			<link rel="alternate" href="http://www.zendcasts.com/forum/post/165/#p165"/>
			<content type="html"><![CDATA[<p>I had the opportunity to work with <a href="http://www.maximebf.com">Maxime Bouroumeau-Fuseau</a> on a project recently and he contributed this ActionHelper, which is my personal favourite way of handling this kind of problem. Maxime has a knack for leveraging PHPDoc comments (notice the @ajax detection in the preDispatch). It reminds me of Attributes in C#:</p><div class="codebox"><strong>PHP Code:</strong><pre><code class="php">&nbsp;
<span class="kw2">&lt;?php</span>
&nbsp;
<span class="coMULTI">/**
&nbsp;* If a controller action has the @ajax tag in its doc comment, then
&nbsp;* the output will be a json string of the controller's json property
&nbsp;*/</span>
<span class="kw2">class</span> App_Controller_Action_Helper_Ajax <span class="kw2">extends</span> Zend_Controller_Action_Helper_Abstract
<span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="coMULTI">/**
&nbsp; &nbsp; &nbsp;* @var bool
&nbsp; &nbsp; &nbsp;*/</span>
&nbsp; &nbsp; protected <span class="re0">$_isAjax</span> = <span class="kw2">false</span>;
&nbsp; &nbsp; 
&nbsp; &nbsp; <span class="coMULTI">/**
&nbsp; &nbsp; &nbsp;* (non-PHPdoc)
&nbsp; &nbsp; &nbsp;* @see library/Zend/Controller/Action/Helper/Zend_Controller_Action_Helper_Abstract#preDispatch()
&nbsp; &nbsp; &nbsp;*/</span>
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> preDispatch<span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;_isAjax = <span class="kw2">false</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$controller</span> = <span class="re0">$this</span>-&gt;<span class="me1">getActionController</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$action</span> = <span class="re0">$this</span>-&gt;<span class="me1">getRequest</span><span class="br0">&#40;</span><span class="br0">&#41;</span>-&gt;<span class="me1">getActionName</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$methodName</span> = <span class="re0">$action</span> . <span class="st0">'Action'</span>;
&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/method_exists"><span class="kw3">method_exists</span></a><span class="br0">&#40;</span><span class="re0">$controller</span>, <span class="re0">$methodName</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$class</span> = <span class="kw2">new</span> ReflectionClass<span class="br0">&#40;</span><a href="http://www.php.net/get_class"><span class="kw3">get_class</span></a><span class="br0">&#40;</span><span class="re0">$controller</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$method</span> = <span class="re0">$class</span>-&gt;<span class="me1">getMethod</span><span class="br0">&#40;</span><span class="re0">$methodName</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/preg_match"><span class="kw3">preg_match</span></a><span class="br0">&#40;</span><span class="st0">'/@ajax/'</span>, <span class="re0">$method</span>-&gt;<span class="me1">getDocComment</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;_isAjax = <span class="kw2">true</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$controller</span>-&gt;<span class="me1">getHelper</span><span class="br0">&#40;</span><span class="st0">'layout'</span><span class="br0">&#41;</span>-&gt;<span class="me1">disableLayout</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; 
&nbsp; &nbsp; <span class="coMULTI">/**
&nbsp; &nbsp; &nbsp;* (non-PHPdoc)
&nbsp; &nbsp; &nbsp;* @see library/Zend/Controller/Action/Helper/Zend_Controller_Action_Helper_Abstract#postDispatch()
&nbsp; &nbsp; &nbsp;*/</span>
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> postDispatch<span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<span class="re0">$this</span>-&gt;_isAjax || !<a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">getActionController</span><span class="br0">&#40;</span><span class="br0">&#41;</span>-&gt;<span class="me1">json</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$json</span> = <span class="re0">$this</span>-&gt;<span class="me1">getActionController</span><span class="br0">&#40;</span><span class="br0">&#41;</span>-&gt;<span class="me1">json</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/is_string"><span class="kw3">is_string</span></a><span class="br0">&#40;</span><span class="re0">$json</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$json</span> = Zend_Json::<span class="me2">encode</span><span class="br0">&#40;</span><span class="re0">$json</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">getActionController</span><span class="br0">&#40;</span><span class="br0">&#41;</span>-&gt;<span class="me1">getHelper</span><span class="br0">&#40;</span><span class="st0">'viewRenderer'</span><span class="br0">&#41;</span>-&gt;<span class="me1">setNoRender</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span class="kw3">header</span></a><span class="br0">&#40;</span><span class="st0">'Content-type: application/json'</span><span class="br0">&#41;</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$json</span>;
&nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span>
&nbsp;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Jon Lebensold]]></name>
				<uri>http://www.zendcasts.com/forum/user/3/</uri>
			</author>
			<updated>2009-09-08T15:55:16Z</updated>
			<id>http://www.zendcasts.com/forum/post/165/#p165</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: ZC32 - Custom Action Helpers for Firebug]]></title>
			<link rel="alternate" href="http://www.zendcasts.com/forum/post/164/#p164"/>
			<content type="html"><![CDATA[<p>By the way, my registration email was auto flagged as spam in gmail, FYI.</p>]]></content>
			<author>
				<name><![CDATA[ryan.horn]]></name>
				<uri>http://www.zendcasts.com/forum/user/52/</uri>
			</author>
			<updated>2009-09-08T14:42:27Z</updated>
			<id>http://www.zendcasts.com/forum/post/164/#p164</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: ZC32 - Custom Action Helpers for Firebug]]></title>
			<link rel="alternate" href="http://www.zendcasts.com/forum/post/163/#p163"/>
			<content type="html"><![CDATA[<p>First off, thanks for the screen casts. I found the site recently and they&#039;ve been helpful thus far (I&#039;m somewhat new to Zend, but come from other frameworks).</p><p>My only comment right now would be that I don&#039;t like holding the individual action methods responsible for disabling the layout, flagging the view renderer, etc. Instead I put that logic in the post dispatch hook and set a flag in each action which should return a JSON response.</p><p>ex:</p><div class="codebox"><pre><code>public function jsonAction() {
    $this-&gt;_isJsonRequest = TRUE;
    ...
}

public function postDispatch() {
    if ($this-&gt;_isJsonRequest === TRUE) {
        $this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender(TRUE);
        $this-&gt;_helper-&gt;getHelper(&#039;layout&#039;)-&gt;disableLayout();
        // Anything else that needs to happen in an action returning a JSON response
    }
}</code></pre></div><br /><p>Not sure if this is the best way, but that&#039;s how I&#039;m doing it. Could probably get more fancy by detecting AJAX requests via the headers sent rather than having to set a flag manually, but maybe another day.</p>]]></content>
			<author>
				<name><![CDATA[ryan.horn]]></name>
				<uri>http://www.zendcasts.com/forum/user/52/</uri>
			</author>
			<updated>2009-09-08T14:16:05Z</updated>
			<id>http://www.zendcasts.com/forum/post/163/#p163</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: ZC32 - Custom Action Helpers for Firebug]]></title>
			<link rel="alternate" href="http://www.zendcasts.com/forum/post/143/#p143"/>
			<content type="html"><![CDATA[<p>hey sNop&nbsp; , <br />This is me tawfek and i would like to thank you for your positive criticism <br />and as Jon Said If you&#039;re not a fan of my voice, My video&nbsp; ,&nbsp; simply download the project file .<br />if you are really happy with zendcasts vedio&nbsp; you should really re think how to spread it the world , aren&#039;t you ??<br />Jon &amp; I hope you find this site informative </p><p>Jon , <br />Thank you very much , i am really appreciate it<br />very much <img src="http://www.zendcasts.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /> <br />tawfek</p>]]></content>
			<author>
				<name><![CDATA[tawfekov]]></name>
				<uri>http://www.zendcasts.com/forum/user/14/</uri>
			</author>
			<updated>2009-09-02T09:16:25Z</updated>
			<id>http://www.zendcasts.com/forum/post/143/#p143</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: ZC32 - Custom Action Helpers for Firebug]]></title>
			<link rel="alternate" href="http://www.zendcasts.com/forum/post/135/#p135"/>
			<content type="html"><![CDATA[<p>Hey sNop,</p><p>Thanks for the feedback! Personally, I think that Tawfek&#039;s contributions to Zendcasts are great. While his English isn&#039;t perfect, I think that first and foremost, this is a learning portal and if he can come and do 3 videos about the Zend Framework (in comparison to the 30 that are done by myself, a native English speaker), it helps enrich the overall content of the site. </p><p>Furthermore, the topics he covers are areas that he obviously demonstrates competency. If you&#039;re not a fan of his voice, simply download the project file. </p><p>When I do my own videos, I have two monitors so that the code I&#039;m writing has already been written and I&#039;m literally transcribing it (that&#039;s why I look like I never make mistakes, something that&#039;s very far from the truth.)</p><p>I hope you enjoy the video that was posted today. </p><p>Best,<br />-<br />Jon Lebensold</p>]]></content>
			<author>
				<name><![CDATA[Jon Lebensold]]></name>
				<uri>http://www.zendcasts.com/forum/user/3/</uri>
			</author>
			<updated>2009-09-01T17:24:07Z</updated>
			<id>http://www.zendcasts.com/forum/post/135/#p135</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: ZC32 - Custom Action Helpers for Firebug]]></title>
			<link rel="alternate" href="http://www.zendcasts.com/forum/post/133/#p133"/>
			<content type="html"><![CDATA[<p>Hi,</p><p>I like your videos, but what bothers me is that you do errors in each word as you write, if you doesn&#039;t have any physical handicap (in this case ignore this part), so pls try to focus on it.</p><p>The other stuff is that your english isn&#039;t good, but this doesn&#039;t bother me because your english is understandable and i&#039;m very happy for every video you post, because In every video i discover something.</p><p>This post is intended as a positive criticism and I don&#039;t want to offend you. <img src="http://www.zendcasts.com/forum/img/smilies/wink.png" width="15" height="15" alt="wink" /></p><p>So i want to thank you for your videos and I look forward to more videos.</p><p>Have i nice day.</p>]]></content>
			<author>
				<name><![CDATA[sNop]]></name>
			</author>
			<updated>2009-09-01T10:29:30Z</updated>
			<id>http://www.zendcasts.com/forum/post/133/#p133</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[ZC32 - Custom Action Helpers for Firebug]]></title>
			<link rel="alternate" href="http://www.zendcasts.com/forum/post/109/#p109"/>
			<content type="html"><![CDATA[<p>I&#039;d like to introduce Tawfek&#039;s sequel to his video covering Debugging in Firebug with the Zend Framework. If you&#039;re looking for a tutorial on how to write a custom Action Helper, or wishing to make your ajax development more robust with logging and profiling, then these 33 minutes will save you a pile of googling.</p><h5>Topics Covered</h5><ul><li><p>Review of firebug</p></li><li><p><strong>2:00:</strong> writing a custom Action Helper</p></li><li><p><strong>5:30:</strong> configuring the Zend Bootstrap</p></li><li><p><strong>10:00:</strong> Testing the Action Helper Through Firebug</p></li><li><p><strong>12:30:</strong> Writing magic methods</p></li><li><p><strong>16:00:</strong> Setting up a JSON-friendly view</p></li><li><p><strong>18:00:</strong> Integrating Zend_Db</p></li><li><p><strong>26:00:</strong> Implementing jQuery</p></li><li><p><strong>29:00:</strong> Console Logging with Firebug and jQuery</p></li></ul>]]></content>
			<author>
				<name><![CDATA[Jon Lebensold]]></name>
				<uri>http://www.zendcasts.com/forum/user/3/</uri>
			</author>
			<updated>2009-08-23T01:18:20Z</updated>
			<id>http://www.zendcasts.com/forum/post/109/#p109</id>
		</entry>
</feed>
