PHP Libraries


Published on

Learn how to include external and third party libraries into your application in prodigyview

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

PHP Libraries

  1. 1. PHP Libraries
  2. 2. OverviewObjectiveLearn the basics of adding external libraries inProdigyView.Requirements Understanding of the DEFINESEstimated Time12 Minutes
  3. 3. Follow Along With Code Example1. Download a copy of the example code at Install the system in an environment you feel comfortable testing in.3. Proceed to examples/system/Libraries_PHP.php
  4. 4. The Purpose of LibrariesThe purpose of libraries is to add third party extensionsinto your application. Libraries differ from applications andplugins in that they do not require a database.In this tutorial, we are going to expand a functionsfunctionality by using libraries
  5. 5. Libraries LocationIf you remember the tutorial on the defines, there was a adefinition called PV_LIBARIES. There is where you willadd your library. Following the examples, our library setupshould looking something like below.
  6. 6. Take Notice!Take a second to notice how the files are named. This willbecome important in a moment. Notice two files end with .class.php Only ends with .php
  7. 7. Disable LibrariesFor our example, we are going to disable the libraries inthe bootstrap. This is done so we can go through theprocess of learning about the libraries. Bootstrap willnormally handle loading the libraries for you.1. Disable the calling of PVLibraries::init 2. Make sure no libraries are loaded
  8. 8. Flip Switch Lets create our method called flipSwitch(). flipSwitch calls certain methods if they exist.Onlyexecutesif class isincluded
  9. 9. Execute Flip SwitchFor our first test, we are going to execute flipSwitch() tosee the results. According to our last slide, we should onlyget results if the class was found.
  10. 10. Add A LibraryAs expected, no classes were found. Now we are going to addthe libraries. The code below looks for our folder‘pv_switch’, which is located in the defined PV_LIBRARIESfolder. And we are only looking for files that end with .class.php 1. The name/folder of the library 2. The allowed extension(s) of the files that will be loaded 3. Loads all the libraries that have been added
  11. 11. Test Number 2With the libraries loaded, lets test flipSwitch() again. Theresult should change.
  12. 12. Add All The libraries We’ve made some progress but we are still missing a class. What went wrong? In our last example we loaded all classes that ended with .class.php. This time we are going to load all the classes in the library.1. Set the name/folder of the library to load 2. With no set extensions, all files that end with .php will be included 3. Load only the library defined
  13. 13. Test 3 ResultsBecause no extension type was set, it will load the defaultof all files that end with .php
  14. 14. The CodeIf you are a little confused about what happened, lookthrough the source code of these files. You will see thatthey contain the classes that were loaded.
  15. 15. Challenge!This is an optional challenge designed to improve yourunderstanding of the libraries and ProdigyView.1. Create a library that adds an Observer(see the observer design pattern tutorial) to the protected method PVLibraries::_loadLibrary().2. Have the class/method added to the observer echo out information about the library added.3. Load only that library.4. Load the library in this example ‘pv_switch’ and record the results.
  16. 16. Review1. Add a library with PVLibraries::addLibrary() method to a queue of libraries to be loaded. The library name should be the same name as a folder in PV_LIBRARIES define.2. Load all the libraries in the library queue using PVLibraries::loadLibraries() method.3. Load a single library with PVLibraries::loadLibrary() method.
  17. 17. API ReferenceFor a better understanding of the libraries, visit the api byclicking on the link below.PVLibraries More TutorialsFor more tutorials, please visit: