Tag Archives: Zend Framework

Create Unit Testing Cases in Zend Framework

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. 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. Setting up the Tests…

Continue Reading

Create CDN View Helper in Zend Framework 2

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. The Helper Class Let us begin by creating the helper class. It can be added within any module, but a suitable place would be within the Application module, provided that you made use of the Skeleton Application. Create a file CdnHelper.php in zf2-tutorial\module\Application with the following subdirectories: There are a few things…

Continue Reading

Zend Framework 2: Send Html Mail with Simple Template

Yesterday, I spent several hours solving this problem. In Laravel Framework, you can do as following: Quite easy, isn't it? However, it's quite tedious using Zend Framework. Step 1: Create Email Template First of all, you need to create a template for mail in views folder, such as /view/mails/reset.phtml. Step 2: Complete Sending Email Function

Continue Reading

Zend Framework 2: Get Parameters

The easiest way to do that would be to use the Params plugin, introduced in beta5. It has utility methods to make it easy to access different types of parameters. As always, reading the tests can prove valuable to understand how something is supposed to be used. Get a single value To get the value of a named parameter in a controller, you will need to select the appropriate method for the type of parameter you are looking for and pass in the name. Default values All of these methods also support default values that will be returned if no parameter with the given name is found. When visiting http://example.com/?orderby=birthdate, $orderBy will have the value birthdate. When visiting http://example.com/, $orderBy will have the default value name. Get all parameters To get all parameters…

Continue Reading

Zend Framework 2: Redirect to 404 page in Controller

I've been getting into trouble several hours with redirect to 404 page in Zend Framework 2. Question in StackOverflow: http://stackoverflow.com/questions/21622849/use-the-same-error-handler-in-different-modules-in-zend-framework-2 Before that, I'm using the following code: It works fine. However, after I create the 404 error page. I found it won't redirect you to the error page with the code above. If you want to redirect to the 404 error page, you should use following code:

Continue Reading
Contact Us
  • Room 311, Zonghe Building, Harbin Institute of Technology
  • cshzxie [at] gmail.com