<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Zend Framework on Infinite Script</title><link>https://www.infinitescript.com/tags/zend-framework/</link><description>Recent content in Zend Framework on Infinite Script</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 03 Mar 2015 02:30:45 +0000</lastBuildDate><atom:link href="https://www.infinitescript.com/tags/zend-framework/index.xml" rel="self" type="application/rss+xml"/><item><title>Create Unit Testing Cases in Zend Framework</title><link>https://www.infinitescript.com/2015/03/create-unit-testing-cases-in-zend-framework/</link><pubDate>Tue, 03 Mar 2015 02:30:45 +0000</pubDate><guid>https://www.infinitescript.com/2015/03/create-unit-testing-cases-in-zend-framework/</guid><description>&lt;p&gt;A solid unit test suite is essential for ongoing development in large projects, especially those with many people involved. Going back and manually testing every individual component of an application after every change is impractical. Your unit tests will help alleviate that by automatically testing your application’s components and alerting you when something is not working the same way it was when you wrote your tests.&lt;/p&gt;&#10;&lt;p&gt;The Zend Framework 2 API uses PHPUnit, and so does this tutorial application. A detailed explanation of unit testing is beyond the scope of this tutorial, so we will only provide sample tests for the components in the pages that follow. This tutorial assumes that you already have PHPUnit installed.&lt;/p&gt;</description></item><item><title>Create CDN View Helper in Zend Framework 2</title><link>https://www.infinitescript.com/2015/02/create-cdn-view-helper-in-zend-framework-2/</link><pubDate>Thu, 26 Feb 2015 11:26:08 +0000</pubDate><guid>https://www.infinitescript.com/2015/02/create-cdn-view-helper-in-zend-framework-2/</guid><description>&lt;p&gt;In this article, you will learn how to create a custom view helper in Zend Framework 2. A concrete example will be used; a helper which generates links for a subdomain, intended for storing static files. This is especially useful if you wish to use a Content Delivery Network (CDN). With very little modification, the helper can be made generic to support links to subdomains for all purposes.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Zend Framework 2 has reached end of life. In 2019 the project moved to the Linux Foundation and was renamed &lt;a href="https://getlaminas.org/"&gt;Laminas&lt;/a&gt;, so the &lt;code&gt;Zend\&lt;/code&gt; namespaces below are now &lt;code&gt;Laminas\&lt;/code&gt; (for example &lt;code&gt;Zend\View\Helper\AbstractHelper&lt;/code&gt; becomes &lt;code&gt;Laminas\View\Helper\AbstractHelper&lt;/code&gt;). The view-helper mechanics are otherwise unchanged, so this post is kept as a historical walkthrough. For a real project, run the namespaces through the &lt;a href="https://docs.laminas.dev/migration/"&gt;Laminas migration guide&lt;/a&gt; and follow the current &lt;a href="https://docs.laminas.dev/laminas-view/v3/helpers/advanced-usage/"&gt;custom view helper docs&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Sending Email with Zend Framework 2 Using Template</title><link>https://www.infinitescript.com/2014/10/zend-framework-2-send-html-mail-with-simple-template/</link><pubDate>Tue, 07 Oct 2014 08:12:31 +0000</pubDate><guid>https://www.infinitescript.com/2014/10/zend-framework-2-send-html-mail-with-simple-template/</guid><description>&lt;p&gt;Sending a templated HTML email is a one-liner in some frameworks, but Zend Framework 2 ships no such helper, so you have to wire up the view renderer, the MIME message, and the transport yourself. This post walks through that setup.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Zend Framework 2 has reached end of life. In 2019 the project moved to the Linux Foundation and was renamed &lt;a href="https://getlaminas.org/"&gt;Laminas&lt;/a&gt;; the &lt;code&gt;Zend\*&lt;/code&gt; classes shown below now live under &lt;code&gt;Laminas\*&lt;/code&gt; (e.g. &lt;code&gt;Laminas\Mail&lt;/code&gt;, &lt;code&gt;Laminas\View&lt;/code&gt;). The technique is unchanged, so this post still applies once you swap the namespaces.&lt;/p&gt;</description></item><item><title>Zend Framework 2: Get Parameters</title><link>https://www.infinitescript.com/2014/02/zend-framework-2-get-parameters/</link><pubDate>Mon, 10 Feb 2014 03:49:35 +0000</pubDate><guid>https://www.infinitescript.com/2014/02/zend-framework-2-get-parameters/</guid><description>&lt;p&gt;The easiest way to read request parameters in a Zend Framework 2 controller is the &lt;a href="https://github.com/laminas/laminas-mvc/blob/master/src/Controller/Plugin/Params.php"&gt;Params plugin&lt;/a&gt;, introduced in beta5. It has utility methods to make it easy to access different types of parameters. As always, reading &lt;a href="https://github.com/laminas/laminas-mvc/blob/master/test/Controller/Plugin/ParamsTest.php"&gt;the tests&lt;/a&gt; can prove valuable to understand how something is supposed to be used.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Zend Framework 2 has been deprecated. The project moved to the Linux Foundation in 2019 and lives on as &lt;a href="https://getlaminas.org/"&gt;Laminas&lt;/a&gt;; the &lt;code&gt;Zend\&lt;/code&gt; namespace became &lt;code&gt;Laminas\&lt;/code&gt;, so the plugin shown here is now &lt;code&gt;Laminas\Mvc\Controller\Plugin\Params&lt;/code&gt; (in the &lt;code&gt;laminas/laminas-mvc&lt;/code&gt; package). The API is unchanged, so the examples below still apply after that rename.&lt;/p&gt;</description></item><item><title>Zend Framework 2: Redirect to 404 page in Controller</title><link>https://www.infinitescript.com/2014/02/zend-framework-2-redirect-to-404-page-in-controller/</link><pubDate>Fri, 07 Feb 2014 10:15:43 +0000</pubDate><guid>https://www.infinitescript.com/2014/02/zend-framework-2-redirect-to-404-page-in-controller/</guid><description>&lt;p&gt;I&amp;rsquo;ve been getting into trouble for several hours with redirecting to the 404 page in Zend Framework 2.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Zend Framework 2 has been deprecated. Zend Framework was migrated to the &lt;a href="https://getlaminas.org/"&gt;Laminas Project&lt;/a&gt; in 2020, where development continues today. The &lt;code&gt;notFoundAction()&lt;/code&gt; technique below still applies in laminas-mvc.&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;p&gt;I asked about this on &lt;a href="https://stackoverflow.com/questions/21622849/use-the-same-error-handler-in-different-modules-in-zend-framework-2"&gt;Stack Overflow&lt;/a&gt;.&lt;/p&gt;&#10;&lt;h2 id="what-didnt-work"&gt;What Didn&amp;rsquo;t Work&lt;/h2&gt;&#10;&lt;p&gt;Before that, I was using the following code:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-php" data-lang="php"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getResponse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;setStatusCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This sets the HTTP status code to 404, which looks fine at first. But it only changes the response header; it doesn&amp;rsquo;t dispatch the error controller, so once I built a custom 404 page I found that it never rendered.&lt;/p&gt;</description></item></channel></rss>