As I said at the beginning, the simplest version of a loading application can be built by explicitly calling some “include()/require()” functions, which are used per file requested. So, to recreate a typical scenario in which these functions are utilized, suppose for a moment that there are two basic files that need to be included within an application, that are defined as follows: ('sample_file1.php')
<?php echo 'This file has been loaded with the require_once() function.' . '<br />'; ?>
('sample_file2.php')
<?php echo 'This file has been also loaded with the require_once() function.' . '<br />'; ?> As shown previously, the two sample files listed above are extremely simple to grasp, so I’m not going to waste your time explaining how they work. Nonetheless, since there’s a fictional application that needs to include the files to do its business, a typical loader file would look like this: ('loader.php' file)
// include first sample file via a require_once() function require_once('sample_file1.php');
// include second sample file via a require_once() function require_once('sample_file2.php'); Definitely, the definition of the “loader.php” file is very basic, but it does show in a nutshell a classic situation, where one “require()” function is called per requested file. In addition, the following output would be produced by the loader file: This file has been loaded with the require_once() function. This file has been also loaded with the require_once() function. This would be quite possibly the most basic implementation of a file loading mechanism in PHP. Despite its simplicity, it works pretty well when building small-scale applications. However, when it comes to developing larger PHP programs, things can get more complex. There will probably be multiple files using many includes. This situation can lead to dealing with tedious debugging and maintenance issues. So, to prevent the vast majority of these eventual problems, it’s necessary to create a file loading system that works in a more modular way, and at the same time allows us to abstract the whole loading process a bit further. This objective can be achieved quite decently by using a simple loader class. Therefore, in the course of the section to come I’m going to discuss how to build such a class in a few basic steps. To learn more about how this procedure will be accomplished, click on the link that appears below and keep reading.
blog comments powered by Disqus |
|
|
|
|
|
|
|