Web Development
Articles, notes, and tutorials filed under Web Development.
Latest articles
Showing 17-22 of 22Unit Testing for Spring MVC Controllers
After all the services, DAO, and support classes are tested then it’s time for the controller. Generally, this is hard to test and most developers (based on observation) would rather just test it via Selenium or worse, by hand. That can work but it makes testing logic branches difficult and not to mention it’s time-consuming. Plus no active developer would be willing to wait for browser tests to run before checking in code. Luckily the Spring MVC Test project can do full controller testing via unit tests, it was such a success that it’s now in Spring MVC core as of version 4.0.5.
Spring 4 MVC Hello World Tutorial Using Maven
In this tutorial, you will learn how to develop a Spring 4 MVC Hello world example. We hope this tutorial will give you a quick start with Spring MVC development using the latest Spring 4 Release. Technologies used: Spring 4.0.4.RELEASE JDK 1.8 Tomcat 7.0.53 Maven 3.2.1 Eclipse Java EE IDE ( Eclipse Kepler) Maven Project Setup In Eclipse Let us start with the creation of a Maven web project in Eclipse. A maven web project archetype will create all the necessary folder structures required for a web project. We assume that you have installed the Maven plugins for Eclipse.
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.
Zend Framework 2: Redirect to 404 page in Controller
I’ve been getting into trouble for several hours with redirecting to the 404 page in Zend Framework 2. The 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: $this->getResponse()->setStatusCode(404); return; 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 the following code:
Use CodeIgniter Resources within Library
To access CodeIgniter’s native resources within your library use the get_instance() function. This function returns the CodeIgniter super object. Normally from within your controller functions, you will call any of the available CodeIgniter functions using the $this construct: $this->load->helper('url'); $this->load->library('session'); $this, however, only works directly within your controllers, your models, or your views. If you would like to use CodeIgniter’s classes from within your own custom classes you can do so as follows:
Generate a Random File Name when Uploading Files in WordPress
The passage is telling you how to rename the file name automatically by WordPress (without using any plugins). Warning: To apply this hack, you’ll have to edit one of WordPress’s core files. Keep in mind that it is never recommended. This hack should be redone if you upgrade WordPress. open the wp-admin/includes/files.php file, and go to line 324 (approximately here). You’ll see the following: $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); Change it as follows: $time_filename = ""; if ($time) { $time_filename = $time; $time_filename = str_replace(["-", " ", ":"], "", $time_filename); } else { $time_filename = date("YmdHis"); } $filename = $time_filename . dechex(mt_rand(65536, 1048575)) . "." . $ext; And the file you upload will automatically be renamed as 20130218180064x268c.ext.