You are previewing Pro PHP and jQuery, Second Edition.
O'Reilly logo
Pro PHP and jQuery, Second Edition

Book Description

Take advantage of the improved performance and reduced memory requirements of PHP version 7, and learn to utilize the new built-in PHP functions and features such as typed variable enforcement with declare(strict_types=1) and the new available data types, scalar type declarations for function arguments and return statements, constant arrays using define(), argument unpacking with the ... operator, integer division with intdiv(), the null coalesce operator, the spaceship operator, new exception types, and improvements to existing features.

Pro PHP and jQuery, Second Edition is for intermediate level programmers interested in building web applications using jQuery and PHP. Updated for PHP version 7 and the latest version of jQuery, this book teaches some advanced PHP techniques and it shows you how to take your dynamic applications to the next level by adding a JavaScript layer using the jQuery framework and APIs.

After reading and using this book, you'll come away having built a fully functional PHP and jQuery web application that you can reapply as a template for your own particular web application.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Contents at a Glance
  5. Contents
  6. About the Authors
  7. About the Technical Reviewer
  8. Part 1: Getting Comfortable with jQuery
    1. Chapter 1: Introducing jQuery
      1. Choosing jQuery Over JavaScript
        1. Understanding JavaScript Libraries
        2. Understanding the Benefits of jQuery
        3. Understanding the History of jQuery
      2. Setting Up a Testing Environment
        1. Installing Firefox
        2. Installing Firebug
      3. Including jQuery in Web Pages
        1. Including a Downloaded Copy of the jQuery Library
        2. Including a Remotely Hosted Copy of the jQuery Library
      4. Setting up a Test File
        1. Introducing the jQuery Function
        2. Selecting DOM Elements Using CSS Syntax
      5. Summary
    2. Chapter 2: Common jQuery Actions and Methods
      1. Understanding the Basic Behavior of jQuery Scripts
      2. Understanding jQuery Methods
        1. Traversing DOM Elements
        2. Creating and Inserting DOM Elements
        3. Accessing and Modifying CSS and Attributes
        4. Affecting Result Sets
        5. Using Animation and Other Effects
        6. Handling Events
        7. Using AJAX Controls
      3. Summary
  9. Part 2: Getting Into Advanced PHP Programming
    1. Chapter 3: Object-Oriented Programming
      1. Understanding Object-Oriented Programming
      2. Understanding Objects and Classes
        1. Recognizing the Differences Between Objects and Classes
        2. Structuring Classes
        3. Defining Class Properties
        4. Defining Class Methods
        5. Using Class Inheritance
        6. Assigning the Visibility of Properties and Methods
        7. Commenting with DocBlocks
      3. Comparing Object-Oriented and Procedural Code
        1. Ease of Implementation
        2. Better Organization
        3. Easier Maintenance
      4. Summary
    2. Chapter 4: Build an Events Calendar
      1. Planning the Calendar
        1. Defining the Database Structure
        2. Creating the Class Map
        3. Planning the Application’s Folder Structure
        4. Modifying the Development Environment
      2. Building the Calendar
        1. Creating the Database
        2. Connecting to the Database with a Class
        3. Creating the Class Wrapper
        4. Adding Class Properties
        5. Building the Constructor
        6. Loading Events Data
        7. Outputting HTML to Display the Calendar and Events
        8. Outputting HTML to Display Full Event Descriptions
      3. Summary
    3. Chapter 5: Add Controls to Create, Edit, and Delete Events
      1. Generating a Form to Create or Edit Events
        1. Adding a Token to the Form
        2. Creating a File to Display the Form
        3. Adding a New Stylesheet for Administrative Features
      2. Saving New Events in the Database
        1. Adding a Processing File to Call the Processing Method
        2. Adding a Button to the Main View to Create New Events
      3. Adding Edit Controls to the Full Event View
        1. Modifying the Full Event Display Method to Show Admin Controls
        2. Adding the Admin Stylesheet to the Full Event View Page
      4. Deleting Events
        1. Generating a Delete Button
        2. Creating a Method to Require Confirmation
        3. Creating a File to Display the Confirmation Form
      5. Summary
    4. Chapter 6: Password Protecting Sensitive Actions and Areas
      1. Building the Admin Table in the Database
      2. Building a File to Display a Login Form
      3. Creating the Admin Class
        1. Defining the Class
        2. Building a Method to Check the Login Credentials
        3. Modifying the App to Handle the Login Form Submission
      4. Allowing the User to Log Out
        1. Adding a Log Out Button to the Calendar
        2. Creating a Method to Process the Logout
        3. Modifying the App to Handle the User Logout
      5. Displaying Admin Tools Only to Administrators
        1. Showing Admin Options to Administrators
        2. Limiting Access to Administrative Pages
      6. Summary
  10. Part 3: Combining jQuery with PHP Applications
    1. Chapter 7: Enhancing the User Interface with jQuery
      1. Adding Progressive Enhancements with jQuery
        1. Setting Progressive Enhancement Goals
      2. Including jQuery in the Calendar App
        1. Creating a JavaScript Initialization File
        2. Creating a New Stylesheet for Elements Created by jQuery
      3. Creating a Modal Window for Event Data
        1. Binding a Function to the Click Event of Title Links
        2. Preventing the Default Action and Adding an Active Class
        3. Extracting the Query String with Regular Expressions
        4. Creating a Modal Window
        5. Retrieving and Displaying Event Information with AJAX
        6. Adding a Close Button
        7. Adding Effects to the Creation and Destruction of the Modal Window
      4. Summary
    2. Chapter 8: Editing the Calendar with AJAX and jQuery
      1. Opening the Event Creation Form
        1. Adding an AJAX Call to Load the Form
        2. Modifying the AJAX Processing File to Load the Form
        3. Making the Cancel Button Behave Like the Close Button
      2. Saving New Events in the Database
        1. Modifying the AJAX Processing File to Handle New Submissions
      3. Adding Events Without Refreshing
        1. Deserializing the Form Data
        2. Creating Date Objects
        3. Appending the Event to the Calendar
        4. Getting the New Event’s Correct ID
      4. Editing Events in a Modal Window
        1. Determining the Form Action
        2. Storing the Event ID if One Exists
        3. Removing Event Data from the Modal Window
        4. Ensuring Only New Events Are Added to the Calendar
      5. Confirming Deletion in a Modal Window
        1. Displaying the Confirmation Dialog
        2. Configuring the Form Submission Event Handler for Deletion
        3. Removing the Event from the Calendar After Deletion
      6. Summary
  11. Part 4: Advancing jQuery and PHP
    1. Chapter 9: Performing Form Validation with Regular Expressions
      1. Getting Comfortable with Regular Expressions
        1. Understanding Basic Regular Expression Syntax
        2. Drilling Down on the Basics of Pattern Modifiers
        3. Getting Fancy with Backreferences
        4. Matching Character Classes
        5. Finding Word Boundaries
        6. Using Repetition Operators
        7. Detecting the Beginning or End of a String
        8. Using Alternation
        9. Using Optional Items
        10. Putting It All Together
      2. Adding Server-Side Date Validation
        1. Defining the Regex Pattern to Validate Dates
      3. Setting up Test Data
        1. Adding a Validation Method to the Calendar Class
        2. Returning an Error if the Dates Don’t Validate
      4. Adding Client-Side Date Validation
        1. Creating a New JavaScript File to Validate the Date String
        2. Including the New File in the Footer
        3. Preventing the Form Submission if Validation Fails
      5. Summary
    2. Chapter 10: Extending jQuery
      1. Adding Functions to jQuery
        1. Adding Your Date Validation Function to jQuery
        2. Modifying the Include Script
        3. Modifying the Initialization Script
      2. Adding Methods to jQuery
        1. Building Your Plug-in
        2. Implementing Your Plug-in
      3. Summary
    3. Appendix A: Brief Notes on PHP 7
      1. Strict Typing
      2. New Exceptions
      3. Constant Arrays
      4. Argument Unpacking
      5. Integer Division
      6. Syntactic Sugar
  12. Index