PHP
WordPress $ is not defined
If you copy a normal jQuery snippet into a WordPress theme or plugin, sooner or later you hit Uncaught ReferenceError: $ is not defined. The confusing part is that jQuery itself is loaded; your other jQuery code may even be working. So why does $ blow up? Why It Happens WordPress ships its own copy of jQuery and loads it in no-conflict mode. On startup it effectively runs: jQuery.noConflict(); noConflict() tells jQuery to give back control of the global $. After it runs, jQuery still points to the library, but $ no longer does; it is left free for some other library to claim.
Zend Framework 2: Get Parameters
The easiest way to read request parameters in a Zend Framework 2 controller is 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. Note: Zend Framework 2 has been deprecated. The project moved to the Linux Foundation in 2019 and lives on as Laminas; the Zend\ namespace became Laminas\, so the plugin shown here is now Laminas\Mvc\Controller\Plugin\Params (in the laminas/laminas-mvc package). The API is unchanged, so the examples below still apply after that rename.
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. Note: Zend Framework 2 has been deprecated. Zend Framework was migrated to the Laminas Project in 2020, where development continues today. The notFoundAction() technique below still applies in laminas-mvc. I asked about this on Stack Overflow. What Didn’t Work Before that, I was using the following code: $this->getResponse()->setStatusCode(404); return; This sets the HTTP status code to 404, which looks fine at first. But it only changes the response header; it doesn’t dispatch the error controller, so once I built a custom 404 page I found that it never rendered.
Install PHP and PHPUnit on Windows/Ubuntu
Note: This post has been updated for PHP 8.5 and PHPUnit 13. The original 2013 version installed PHPUnit through PEAR (go-pear, pear channel-discover pear.phpunit.de), but PEAR has since been retired and PHPUnit no longer ships through it. The current approach is to install PHPUnit with Composer or as a standalone PHAR, both shown below. PHPUnit is the de-facto testing framework for PHP. This guide gets PHP and PHPUnit running on Windows and Ubuntu, then writes and runs a first test to confirm the setup works.
Convert Excel Date into Timestamp in PHP
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.
Student Management System
GitLab Open Source Introduction The Student Management System is a PHP/CodeIgniter web application built for the School of Software at Hefei University of Technology to replace a fully paper-based Comprehensive Evaluation (综合测评): an annual multi-dimensional student assessment covering academic performance, peer review, extracurricular involvement, and community service, used to determine scholarship rankings. According to school news coverage, what previously took over 5 days of manual tallying per cohort was reduced to microsecond-level computation. The project was selected as a National Undergraduate Innovation Training Program (国家级大学生创新训练计划项目) project in 2013.
Use CodeIgniter Resources within Library
To access CodeIgniter’s native resources from inside your own library, use the get_instance() function. It returns the CodeIgniter super object, the same one you reach through $this inside a controller, so your library can load helpers, read config, or call any other class the framework has instantiated. Note: get_instance() is a CodeIgniter 3.x (and earlier) technique. CodeIgniter 4 dropped the global super object. There you reach framework features through Services, such as service('session') or \Config\Services::session(), or by injecting the dependencies your class needs through its constructor. Everything below applies to CodeIgniter 3.x.
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). A Word of Warning 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. Editing the Upload Handler Open the wp-admin/includes/files.php file, and go to line 324 (approximately here). You’ll see the following: