Category Archives: PHP

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

Difference Between require() and include() in PHP

One of the most common questions I get asked by PHP beginners is, Why is there 4 ways to include a file on your page? There is include(), include_once(), require() and require_once(). What do these do? What's the difference between them? In this article we're going to look at all these different functions and will talk about an example of when you need to use each of them. include() The include function is used in PHP when you want to include a file within the current process. It takes one argument which will be a string to the file path you want to include. The code inside the included file will then run when the include function is called. This…

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

WordPress $ is not defined even if jQuery is loaded

Many times while using WordPress, if we try to use "e;$” to access jQuery, we get an error the "e;$ is not defined”. This happens because the jQuery library which is included in WordPress loads in "e;no conflict” mode. In the no conflict mode jQuery returns the control of "e;$”, and it is no longer accessible as function, variable or alias for jQuery. WordPress does this in order to prevent compatibility problems with other JavaScript libraries that can be loaded. To solve this we can use "e;jQuery” instead of "e;$”. So, instead of using the standard code with "e;$” we can use the following code, which uses "e;jQuery” instead of "e;$” If you want to use the default "e;$” symbol,…

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, $orderBy will have the value birthdate. When visiting, $orderBy will have the default value name. Get all parameters To get all parameters…

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