Category Archives: PHP

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: 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:

Continue Reading

Install PHP and PHPUnit on Windows/Ubuntu

Download PHP Windows downloads of PHP are available here. If you are not sure of which version to get, check out this Stack Overflow page. I used the VC11 thread-safe PHP 5.5.0 download. Install PHP Once you’ve downloaded the installer, run it and install PHP in C:php (or wherever you like, but remember that the path should not contain spaces). Choose your webserver (or none if you don’t have a webserver installed) and select any additional components as needed, including PEAR. Once PHP is installed open a command prompt. Check that PHP is set up correctly by running It should give you output something like If you don’t get this output something has gone wrong with the PHP install or in the modification of…

Continue Reading

Convert Excel Date into Timestamp

Excel stores a date internally as a number of days since January 1, 1900.For example: "June 9th, 2011 10:30 AM" would be stored as "40703.4375".40703 is the number of full days since 01/01/1900 and 0.4375 represents the time (10.5/24 = 0.4375). When you process dates read from an Excel spreadsheet (e.g. using PHPExcel) you often want to convert them into a UNIX timestamp i.e. a number of seconds elapsed since midnight of January 1, 1970 UTC. Here is a PHP code to do that: Although the code above is written in PHP the function should be very similar in any other language e.g. C# or java. If the provided date is earlier than 1/1/1970 then the minimal timestamp value will be returned. Alternative…

Continue Reading

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, 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: First, assign the CodeIgniter object to a variable:[php]$CI =& get_instance();[/php]Once you've assigned the object to a variable, you'll use that variable instead of $this: You'll notice that the above get_instance() function is being passed by reference: This is very important. Assigning by reference allows you to use the original CodeIgniter object rather than creating a copy…

Continue Reading

Rename Files During Upload within WordPress Backend

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: Change it as follows: And the file you upload will automatically be renamed as 20130218180064x268c.ext.

Continue Reading
Contact Us
  • Nanyang Technological University, Singapore
  • root [at] haozhexie [dot] com