PHP Libraries

0

No comments posted yet

Comments

Slide 1

PHP Libraries

Slide 2

Overview Objective Learn the basics of adding external libraries in ProdigyView. Requirements Understanding of the DEFINES Estimated Time 12 Minutes

Slide 3

Follow Along With Code Example Download a copy of the example code at www.prodigyview.com/source. Install the system in an environment you feel comfortable testing in. Proceed to examples/system/Libraries_PHP.php

Slide 4

The Purpose of Libraries The purpose of libraries is to add third party extensions into your application. Libraries differ from applications and plugins in that they do not require a database. In this tutorial, we are going to expand a functions functionality by using libraries

Slide 5

Libraries Location If you remember the tutorial on the defines, there was a a definition called PV_LIBARIES. There is where you will add your library. Following the examples, our library setup should looking something like below.

Slide 6

Take Notice! Take a second to notice how the files are named. This will become important in a moment. Notice two files end with .class.php Only ends with .php

Slide 7

Disable Libraries For our example, we are going to disable the libraries in the bootstrap. This is done so we can go through the process of learning about the libraries. Bootstrap will normally handle loading the libraries for you. 1. Disable the calling of PVLibraries::init 2. Make sure no libraries are loaded

Slide 8

Flip Switch Lets create our method called flipSwitch(). flipSwitch calls certain methods if they exist. Only executes if class is included

Slide 9

Execute Flip Switch For our first test, we are going to execute flipSwitch() to see the results. According to our last slide, we should only get results if the class was found.

Slide 10

Add A Library As expected, no classes were found. Now we are going to add the libraries. The code below looks for our folder ‘pv_switch’, which is located in the defined PV_LIBRARIES folder. 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

Slide 11

Test Number 2 With the libraries loaded, lets test flipSwitch() again. The result should change.

Slide 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

Slide 13

Test 3 Results Because no extension type was set, it will load the default of all files that end with .php

Slide 14

The Code If you are a little confused about what happened, look through the source code of these files. You will see that they contain the classes that were loaded.

Slide 15

Challenge! This is an optional challenge designed to improve your understanding of the libraries and ProdigyView. Create a library that adds an Observer(see the observer design pattern tutorial) to the protected method PVLibraries::_loadLibrary(). Have the class/method added to the observer echo out information about the library added. Load only that library. Load the library in this example ‘pv_switch’ and record the results.

Slide 16

Review 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. Load all the libraries in the library queue using PVLibraries::loadLibraries() method. Load a single library with PVLibraries::loadLibrary() method.

Slide 17

API Reference For a better understanding of the libraries, visit the api by clicking on the link below. PVLibraries www.prodigyview.com More Tutorials For more tutorials, please visit: http://www.prodigyview.com/tutorials

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

Tags: design patterns extensions libraries observer php prodigyview programming third-party

URL: