Web Development
Articles, notes, and tutorials filed under Web Development.
Latest articles
Showing 9-16 of 22Create 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.
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:
Sending Email with Spring MVC Using Template
This tutorial provides a sample spring MVC application that allows user sending an e-mail message. In this tutorial, you are supposed to familiar with Java EE development as well as developing Spring MVC-based applications. Spring Framework’s Support for E-mail Based on JavaMail, Spring framework provides high-level abstraction API which greatly simplifies e-mail sending process. Let’s take a brief look at this API in the following class diagram: To send e-mail messages, we can use an implementation of interface MailSender – the JavaMailSenderImpl class which is built upon on JavaMail. It’s convenient to configure this implementation as a bean in Spring’s context:
Spring AOP Example Using Annotation
Spring Framework is developed on two core concepts – Dependency Injection and Aspect-Oriented Programming (AOP). Today we will look into the core concepts of Aspect-Oriented Programming and how we can implement it using Spring Framework. Aspect-Oriented Programming Overview Most of the enterprise applications have some common crosscutting concerns that is applicable for different types of Objects and modules. Some of the common crosscutting concerns are logging, transaction management, data validation, etc. In Object-Oriented Programming, modularity of application is achieved by Classes whereas in Aspect-Oriented Programming application modularity is achieved by Aspects and they are configured to cut across different classes.
Sending Email with Zend Framework 2 Using Template
Yesterday, I spent several hours solving this problem. In Laravel Framework, you can do as following: Mail::send("mails.reset", $data, function ($message) use ($email) { $message ->from("noreply@infinitescript.com", "CourseOcean") ->subject("Reset Your Password"); $message->to($email); }); Step 1: Create an Email Template First of all, you need to create an email template in the views folder, such as /view/mails/reset.phtml. <table cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <td style=" padding: 15px 15px 0 15px; background: #fff; border-radius: 4px 4px 0 0; " > <div> <img src="http://lab.haozhexie.com/CourseOcean/img/logo.webp" alt="CourseOcean" height="85" width="290" /> </div> </td> </tr> <tr> <td style=" padding: 15px; background: #fff; border-radius: 0 0 4px 4px; font-size: 12px; " > We received a request to reset the password for your account, <?=$this->username?>.<br /><br /> If you made this request, click the link below. If you didn't make this request, you can ignore this email.<br /><br /> <a href="http://lab.haozhexie.com/CourseOcean/accounts/resetPassword?email=<?=$this->email?>&keycode=<?=$this->keycode?>" target="_blank" style="color: #005399; text-decoration: none" >http://lab.haozhexie.com/CourseOcean/accounts/resetPassword?email=<?=$this->email?>&keycode=<?=$this->keycode?></a ><br /><br /> Yours, <br /> CourseOcean.<br /><br /> <div style=" border-top: 3px solid #eee; color: #999; font-size: 11px; line-height: 1.2; " > <br />Powered by <a href="http://lab.haozhexie.com/CourseOcean/" target="_blank" style="color: #005399; text-decoration: none" >CourseOcean</a >. All rights reserved.<br /> </div> </td> </tr> </tbody> </table> Step 2: Complete Sending Email Function function sendResetPasswordEmail($username, $email) { $keycode = $this->generateRandomString(32); $view = new \Zend\View\Renderer\PhpRenderer(); $resolver = new \Zend\View\Resolver\TemplateMapResolver(); $resolver->setMap([ "mailTemplate" => __DIR__ . "/../../../view/mails/reset.phtml", ]); $view->setResolver($resolver); $viewModel = new ViewModel(); $viewModel->setTemplate("mailTemplate")->setVariables([ "username" => $username, "email" => $email, "keycode" => $keycode, ]); $bodyPart = new \Zend\Mime\Message(); $bodyMessage = new \Zend\Mime\Part($view->render($viewModel)); $bodyMessage->type = "text/html"; $bodyPart->setParts([$bodyMessage]); $message = new \Zend\Mail\Message(); $message ->addFrom("noreply@infinitescript.com", "CourseOcean") ->addTo($email) ->setSubject("Reset Your Password") ->setBody($bodyPart) ->setEncoding("UTF-8"); $transport = new \Zend\Mail\Transport\Sendmail(); $transport->send($message); }
WordPress $ is not defined
Many times while using WordPress, if we try to use “$” to access jQuery, we get an error the “$ is not defined”. This happens because the jQuery library which is included in WordPress loads in “no conflict” mode. In the no conflict mode jQuery returns the control of “$”, and it is no longer accessible as a function, variable, or alias for jQuery. WordPress does this in order to prevent compatibility problems with other JavaScript libraries that can be loaded.
Integrate Spring MVC with Log4j
It’s quite straightforward to integrate Log4j into the Spring MVC application. First, include Log4j.jar library into your project dependency, then create a log4.properties file to define the Log4j’s appender and put this file into the project classpath, Done. In the tutorial, we show you how to integrate the Log4j 1.x logging framework into the Spring MVC application. Add Log4j Library to Your Project Download the Log4j library from the official website, or via Maven :
How does Ajax Work
Ajax is a term coined by Jesse James Garrett and that became popular since the publication of the article Ajax: A New Approach to Web applications, published in February 2005, is a shortcut for Asynchronous JavaScript and XML. The normal behavior of the Internet that involves sending pages to the browser is completely changed by the use of Ajax. Ajax has become commonplace with its integration in HTML 5 and JavaScript frameworks, and in fact, the interest of developers has moved to HTML 5 for its new tags and APIs that accompany it. Among these, WebSocket appears as the successor to Ajax, because it is a superior means of communication between an application and the server or the backend.